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

form_for vs form_tag

Hey guys, could someone please explain to me when would I use form_for as opposed to form_tag? Can you give me some examples? I know form_for is used when interacting with a model but do you actually need it when you are just creating a record in the database such as user registration (controller1) or reading the database to validate user login (controller2)?

1 Answer

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Vidhya Kumar the difference is that form_for takes an object, like a model, and can use that in the forms. You get the benefits of using f.label, f.text_field, etc. When you use the form_tag method, it just created a form tag.