【发布时间】:2011-09-09 19:27:27
【问题描述】:
Rails 没有将参数中的任何内容发布到操作时遇到问题。 我正在使用带有嵌套复数资源的单数资源,该资源可能会或可能会 不是问题出在哪里(Rails 在 form_for 和单数方面存在问题 资源 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 %>
创建动作:
def create
@event = Event.find(params[:event_id])
@action = @event.actions.create(params[:action])
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" 行, 我看到在我的参数中我得到一个参数“:格式” 这似乎是事件的 ID。
但是,我仍然没有得到动作参数。 :(
【问题讨论】:
-
移除遥控器并查看日志
-
我这样做了,我看到一个带有 id 的格式参数(而不是 event_id)被传递。但是我仍然看不到该操作的参数?我不明白。
-
请用这些额外信息更新您的问题
标签: ruby-on-rails forms