Test Your Knowledge
Quiz
How much change did the controller need to handle file uploads?
Why did the
form_for
method suddenly explode in complexity when the MIME type of the returned data changed?What goes into a migration when you add a field to a table?
How do you make methods invisible (and uncallable) outside of their class?
Are form builders for binding presentation to a specific piece of your model, or for supporting more general form construction?
Do builders map to controllers automatically?
Why (and when) are form builders worth the extra trouble of creating them?
Answers
The controller needed no change at all. All of the changes were in the views, to give users the ability to upload and display the file, and in the model, to handle the file when it arrived and when it was needed.
The
form_for
method looks much more complex because weâd been using a simplified form of it that assumes a lot of defaults. Change those defaults, and you need to specify much, much more.A migration that adds a field needs an
add_column
call defining the field in theself.up
method and aremove_column
call in theself.down
method.Placing method definitions after the
private
keyword makes them usable only within the class.They can be used for both general form construction and the creation of reusable components tightly bound to a particular model. You can even mix the two approaches in the same class.
No. Helper methods can bind to controllers through naming conventions, but using form builders requires ...
Get Learning Rails: Live Edition 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.