新的"开发者"这里。我正在尝试学习如何为现有应用程序创建表单,并且我将我的头发撕掉了。
控制器:
class DigitalRecipientsController < ApplicationController
def update
@line_item = line_item params[:id]
@recipients = @line_item.recipients
recipient = @recipients.create! :name => @new_name, :email => @new_email
end
end
routes.rb:
resources :digital_recipients
模板html.erb,(在@ line_items.each | line_item |的循环中):
<%= form_for line_item, :url => {:controller => 'digital_recipients', :action => 'update'} do |f| %>
<%= f.label 'name: ' %><%= f.text_field(:name, value: @new_name) %>
<%= f.label ', email: ' %><%= f.text_field(:email, value: @new_email) %>
<%= f.submit %>
<% end %>
此抛出和异常:
No route matches {:action=>"update", :controller=>"digital_recipients"}
我不明白为什么?!!?如何将此表单指向该控制器的方法&#39;更新&#39;?
非常感谢任何帮助!非常感谢你。
答案 0 :(得分:0)
试试这个
<%= form_for line_item, url: digital_recipient_path(line_item), method: :put do |f| %>
<%= f.label 'name: ' %><%= f.text_field(:name, value: @new_name) %>
<%= f.label ', email: ' %><%= f.text_field(:email, value: @new_email) %>
<%= f.submit %>
<% end %>