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_formethod and theform_tagmethod explored earlier?How do you add HTML attributes to the HTML generated by Rails’ helper methods?
Why does Rails’
check_boxhelper 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_formethod creates an entire environment with context based on anActiveRecordclass that other helper methods can use to create their own fields within the form. Theform_tagmethod is mostly about wrapping the form in an appropriate form tag. The helpers called inside ofform_tagare on their own.You can generate HTML attributes using named parameters put inside of a parameter named
:html, such as:html => { :id => 'person_form', :class => ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access