13

I have a form, that when POSTed, renders another form. What I would like to do is to pass the parameters from the first form, into certain hidden fields of the second form.

The second form is using a form_for form helper, and what I'm trying to do is to get it to accept the parameters that are being posted to it.

Here's what the form looks like:

    <%= form_for(@phone) do |f| %>
        <%= f.hidden_field :original_number, params[:original_number] %>


        <%= f.hidden_field :name, params[:name] %>
        <%= f.hidden_field :twilio_number,  number.phone_number %>

        <div class="found_list">
            <div class="found_phone_number">
                <%= f.label :number, number.friendly_name) %>
            </div>
            <div class="choose_found_number">
            <%= f.submit "Choose This Number", :class => "btn btn-large btn-success" %>
            </div>
        </div>
            <hr>
    <% end %>

When I do something like

<%= f.hidden_field :original_number, params[:original_number] %>

The action gives me the error:

NoMethodError in Find_numbers#create

Showing C:/Sites/dentist/app/views/phones/new.html.erb where line #17 raised:

undefined method `merge' for "1231231234":String

The "1231231234" is the parameter that is being POSTed to the form, but it doesn't seem to accept it.

Do you have an idea of how I would get the form to accept the parameter?

When I removed the params[], the error doesn't happen, but the parameters also don't populate in the hidden fields.

4

1 回答 1

35

second parameter in hidden_field should be an option hash, not a value

<%= f.hidden_field :original_number, :value => params[:original_number] %>
于 2012-10-04T16:55:30.480 回答