Leave a comment

Creating a Simple Form with Rails

This is a great write up that I thought that I would share 😉

Cindi Writes Code

Form helpers are designed to make working with resources much easier compared to plain HTML.

http://api.rubyonrails.org/ – search for “form_for” to find under ActionView::Helpers::FormHelper

We can use a form builder to create a form within an .erb template. The main form builder for Rails is provided by a helper method called “form_for”.  Example code:

The form_for helper creates a form that allows the user to create or update the attributes of a specific model object.

The method can be used in several slightly different ways, depending on how much you wish to rely on Rails to infer automatically from the model how the form should be constructed. For a generic model object, a form can be created by passing form_for a string or symbol representing the object we are concerned with.

In the example above, we are passing in the article object (“:article”).

The variable f yielded to the…

View original post 977 more words

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: