2016-08-17 31 views
0

我想传递一个参数到我的f.text_field,但我不断收到一个错误。 “错误的参数数目(3 1..2)”如何将参数检索到f.text_field?

<%= f.text_field :location, params[:location], placeholder: "Enter Zipcode", class: "form-control" %> 

回答

1
<%= f.text_field :location, placeholder: "Enter Zipcode", value: params[:location], class: "form-control" %> 
2
def edit 
    @city = City.find_by(id: params[:id]) 
end 

<%= form_for(@city, :html => { :multipart => true, :class => "form-horizontal" }) do |f| %> 
    <%= f.text_field :location, class: "form-control", required: :required, placeholder: "Enter Zipcode" %> 
<% end %>