Test Your Knowledge

Quiz

  1. How many properties and data types can you specify in a call to script/generate scaffold?

  2. Where does Rails actually specify the data types for properties?

  3. What is the difference between the form_for method and the form_tag method explored earlier?

  4. How do you add HTML attributes to the HTML generated by Rails’ helper methods?

  5. Why does Rails’ check_box helper create an extra hidden form field?

  6. How do you specify which option in a selection box is the default?

  7. Where should you put helper methods you create?

  8. Why would you use a partial?

Answers

  1. 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.

  2. 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.)

  3. The form_for method creates an entire environment with context based on an ActiveRecord class that other helper methods can use to create their own fields within the form. The form_tag method is mostly about wrapping the form in an appropriate form tag. The helpers called inside of form_tag are on their own.

  4. 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.