Test Your Knowledge
Quiz
How many properties and data types can you specify in a call to
script/generate scaffold
?Where does Rails actually specify the data types for properties?
What is the difference between the
form_for
method and theform_tag
method explored earlier?How do you add HTML attributes to the HTML generated by Railsâ helper methods?
Why does Railsâ
check_box
helper create an extra hidden form field?How do you specify which option in a selection box is the default?
Where should you put helper methods you create?
Why would you use a partial?
Answers
As many as your operating system will let you put on a single command line. They get inconvenient quicklyâif you want to add a huge number, you may want to edit that command line in a text editor and make sure itâs right before putting it in.
The only place that the data types are specified in Rails is in the migrations. Once the migrations build the database, Rails gets its understanding of the data types from the database. (This is very different from Java development, for example.)
The
form_for
method creates an entire environment with context based on anActiveRecord
class that other helper methods can use to create their own fields within the form. Theform_tag
method is mostly about wrapping the form in an appropriate form tag. The helpers called inside ofform_tag
are on their own.You can generate HTML attributes using named parameters put inside of a parameter named
:html
, such as:html => { :id => 'person_form', ...
Get Learning Rails now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.