Ruby on Rails Flashcards
Gem Specification:
gem ‘rails’, ‘4.0.0’
is “absolute”, only version 4.0.0 will be used
Gem Specification:
gem ‘rails’, ‘>= 4.0.0’
is “optimistic”, any version newer than 4.0.0 will be used
Gem Specification:
gem ‘rails’, ‘~> 4.0.0’
“pessimistic”;
~> 4.0.0 means use
any version greater than 4.0.0 and less than 4.1 (any patch version can be used). ~> 4.0
means use any version greater than 4.0 and less than 5.0 (any minor version can be used).
Changes in routes file
When you change the config/routes.rb file, you must restart your application server to see
the new behavior.
Can a controller use data from more than one model?
. In Rails, though a controller can use data from more than one model,
there is often a model with the same name as a controller
How do you pass variables to the view file from the controller?
Any instance variables (variables named with the @
character) will be available in the corresponding view file.
understanding params (add more)
params = {controller: ‘contacts’,
action: ‘process_form’,
contact: {name: ‘Daniel’ , email: ‘daniel@danielkehoe.com@’, content: ‘hi!’}
}
skinny controller, fat model
Controllers should
contain only enough code to instantiate a model and handle rendering. If you think about it,
adding a subscriber to the MailChimp database is a data operation, and all data
manipulation should be handled by a model.
How do you run bundle without installing production gems?
bundle install –without production
Why do you need to precompile assets?
If you don’t precompile assets for production, all web pages will look strange. They won’t
have CSS styling.
How do instance variables help performances?
Setting an instance variable (in controller) caches the data so it doesn’t make a new database call each find the instance is searched for.
What does t.timestamps create?
It will create two columns inside our table titled created_at and updated_at
What are the 7 core actions of rails’ REST implementation?
index new create show update edit destroy
What is form_for and how do you use it?
form_for is a Rails helper method which takes one parameter, in this case @article and a block with the form fields. The first line basically says “Create a form for the object named @article, refer to the form by the name f and add the following elements to the form…”
Example:
<li></li>
</ul>
<p>
<br></br>
</p>
<p>
<br></br>
</p>
<p>
</p>
How is form data accessible?
The data from the form will be accessible through the params method.