Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby on Rails 5 Basics Adding a Model Attribute Updating Partials

How does :body link back to the text stored in the body?

I see that for the form.label if I change :body to :name or any other name it changes the name of the html text but for form.text_area if I change the name from body it wont load the text.

Do :body have two different meanings for form.label and form.text_area?

Can someone explain what the :title or :body represents?

Ari Misha
Ari Misha
19,323 Points

Hiya David! Can you post the whole code in order for me to understand what actually your :body or :name represents? OR atleast post your view file/partial containing these symbols? (:

1 Answer

The form.label :body just refers to the little heading for each form element. Usually, when you have a form, each area is labeled as to what you need to enter...like name, email or password so that you know what info to put in which area. The form.text_area :body is referring to what info that particular table (Posts) is requiring in the database...so for the video example a Post contains a :title and a :body (which would be the text body of the post).

Jay McGavren
Jay McGavren
Treehouse Teacher

To expand on this: every Rails model has accessor methods for its attributes (the data it holds). So the Post model has a title method that's used to retrieve its title, and a body method that's used to retrieve its body. The symbols that you pass to the form object's label, text_area, etc. methods should match the name of one of those attribute accessor methods.

So if you're presenting an edit form, form.text_field :title will access the title method of the Post object, and pre-populate a form field with the title method's return value. It will also cause the form to include a title parameter in the submitted form data (which gets passed to the title= method of the Post model to set the updated title).