Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 Rails 4集合\u选择渲染时不自动填充_Ruby On Rails 4_Form For - Fatal编程技术网

Ruby on rails 4 Rails 4集合\u选择渲染时不自动填充

Ruby on rails 4 Rails 4集合\u选择渲染时不自动填充,ruby-on-rails-4,form-for,Ruby On Rails 4,Form For,因此,基本上,我有一个新的视图,当输入失败时,我希望视图用以前输入的数据重新渲染。出于某种原因,除了集合_以_forhelper的形式选择之外,所有内容都会加载原始请求的数据。我一点也不确定为什么 <%= form_for(@match) do |f| %> <b> Winner </b> <%= f.collection_select :user0_id, User.order(:name),:id,:name, include_b

因此,基本上,我有一个新的视图,当输入失败时,我希望视图用以前输入的数据重新渲染。出于某种原因,除了集合_以_forhelper的形式选择之外,所有内容都会加载原始请求的数据。我一点也不确定为什么

  <%= form_for(@match) do |f| %>
    <b> Winner </b>
    <%= f.collection_select :user0_id, User.order(:name),:id,:name, include_blank: true %>

    <b> Loser </b>
    <%= f.collection_select :user1_id, User.order(:name),:id,:name, include_blank: true %>

    <b> Score </b>
    <%= f.select :score,  (0..21) %>

    <b> Password </b>
    <%= f.password_field :password %>

    <%= f.submit "Submit match", class: "btn btn-lg btn-primary" %>
  <% end %>

我正在验证params散列是否返回了所有正确的值,但由于某些原因,它不是自动填充集合。非常感谢您的帮助。

您能给我们看看返回的参数散列吗?Authentity\u token:--------------match:!ruby/hash:ActionController::Parameters user0\u id:'15'user1\u id:'56'cupsleft:'5'密码:''提交:提交匹配操作:创建控制器:匹配可能是因为user0、user1只是match.rb中的attr\u访问器,而不是实际的数据属性吗?每个匹配都有许多用户通过一个关系,我不知道如何将用户作为数组属性传递,所以它有点粗糙。嗯。。。user0\u id和user1\u id的值决定了自动填充集合集的值,让我做一些实验,看看我得到了什么。
def new
   @match = Match.new
end

def create

@match = Match.new(match_params)

if !match.save?
  flash.now[:notice] = "Match was not saved!"
  render :new
else
  # success code here
end