Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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 Rails在单个资源窗体上嵌套资源_Ruby On Rails_Forms - Fatal编程技术网

Ruby on rails Rails在单个资源窗体上嵌套资源

Ruby on rails Rails在单个资源窗体上嵌套资源,ruby-on-rails,forms,Ruby On Rails,Forms,Rails没有将参数中的任何内容发布到操作中,我遇到了一个问题。 我使用的是一个单数资源和一个嵌套的复数资源,可能是,也可能是 不是问题的根源(Rails的表单和单数都有问题 资源URL) 不管怎么说,我的路线中有这样一条: resource :event do resources :actions, :only => [:create], :controller => "events/actions" end 观点: <%= form_for([@event, Ac

Rails没有将参数中的任何内容发布到操作中,我遇到了一个问题。 我使用的是一个单数资源和一个嵌套的复数资源,可能是,也可能是 不是问题的根源(Rails的表单和单数都有问题 资源URL)

不管怎么说,我的路线中有这样一条:

resource :event do
    resources :actions, :only => [:create], :controller => "events/actions"
end
观点:

<%= form_for([@event, Action.new], :remote => true) do |f| %>
  <div class="field">
    <%= f.label :team_id %>
    <br />
    <%= f.text_field :team_id %>
  </div>
  <div class="field">
    <%= f.label :message %>
    <br />
    <%= f.text_field :message %>
  </div>
  <div class="field">
    <%= f.label :score %>
    <br />
    <%= f.number_field :score %>
  </div>
  <br />
  <%= f.submit "Update score" %> or <%= link_to "cancel", "#", :id => "cancel" %>
<% end %>
好的,不用担心。 但当我从Rails获得参数时,什么都没有了(

参数:

Started POST "/event/actions.4e67f09349ae71090c00000e"
Processing by Events::ActionsController#create as
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"stuff", "commit"=>"Update score"}

Completed 500 Internal Server Error in 31ms
这是怎么回事

编辑:

如果删除视图中的“:remote=>true”行, 我看到在我的参数中有一个参数“:format” 它似乎是事件的ID


但是,我仍然没有获得操作参数。(

理想情况下,我希望看到这些事件和操作模型-我怀疑这就是问题所在。没有看到这些,我有一些建议:

  • 事件模型中是否设置了“接受\u嵌套的\u属性\u for:action”

  • 从两个模型中删除任何“attr_accessible”行,看看是否可行。(请记住,您需要为父模型中的嵌套表单设置可访问属性)

  • “Action”似乎是一个轻率的模型名称。rails可能正在用与实际操作相关的内容覆盖“Action”方法


希望这有帮助-如果您仍然无法找到解决方案,我建议发布模型。

理想情况下,我希望看到这些事件和行动模型-我怀疑这就是问题所在。如果没有看到这些,我有一些建议:

  • 事件模型中是否设置了“接受\u嵌套的\u属性\u for:action”

  • 从两个模型中删除任何“attr_accessible”行,看看是否可行。(请记住,您需要为父模型中的嵌套表单设置可访问属性)

  • “Action”似乎是一个轻率的模型名称。rails可能正在用与实际操作相关的内容覆盖“Action”方法


希望这对您有所帮助-如果您仍然无法找到解决方案,我建议您发布模型。

删除遥控器并查看日志。我做到了这一点,我看到了一个格式参数(而不是事件id)通过id。但我仍然没有看到操作的参数?我不明白。请使用这些额外信息更新您的问题移动远程设备并查看日志。我看到了一个格式参数(而不是事件id)通过id。但是我仍然没有看到操作的参数?我不明白。请用这些额外的信息更新您的问题。您是对的。因为Rails对实际操作(而不是模型)使用参数[:action],所以我的模型把一切都搞砸了。我已经重命名了它,现在它工作得很好。谢谢!您是对的。因为Rails使用参数[:action]对于实际操作(而不是模型),我的模型把一切都搞糟了。我已经重命名了它,现在它工作得很好。谢谢!
Started POST "/event/actions.4e67f09349ae71090c00000e"
Processing by Events::ActionsController#create as
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"stuff", "commit"=>"Update score"}

Completed 500 Internal Server Error in 31ms