如何将参数检索到f.text_field?

时间:2016-08-17 02:27:58

标签: ruby-on-rails ruby-on-rails-4

我正在尝试将参数传递给我的f.text_field但我一直收到错误。 "错误的参数数量(3为1..2)"

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

2 个答案:

答案 0 :(得分: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 %>

答案 1 :(得分:1)

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