views:

16

answers:

1

I assume the values must be passed back to the controller for use, but everything I have tried seems to only get values that have already saved in the db.

+2  A: 

When a form is submitted, the controller will always have access to a hash called "params", which will contain all of the submitted data.

For example, if your form contains a textbox with a name "foo"

<input type="text" name="foo" />

the value can be retrieved in the controller using

fooValue = params[:foo]

You can use this to build a new instance of a model, containing the submitted values from the form as follows:

in your form:

<% form_for :person, @person, :url => { :action => "create" } do |f| %>
  <%= f.text_field :first_name %>
  <%= f.text_field :last_name %>
  <%= submit_tag 'Create' %>
<% end %>

then, in your controller:

@newPerson = Person.new(params[:person]; #this will pass the whole group of values within that person form to the "new" method
JacobM