我有一个表单,在'order_items'控制器上提交自定义操作'add_participants'。它似乎提交了正确的操作,但错误引用了无关的视图,该视图与'order_items #new'相关联。
我尝试过的内容包括:
错误
ArgumentError in OrderItems#add_participants
Showing /path/to/app/views/order_items/new.html.erb where line #7 raised:
First argument in form cannot contain nil or be empty
Extracted source (around line #7):
<%= form_for @order_item do |f| %>
<div class="field">
<%= f.hidden_field :company_id, :value => '2' %>
app/views/order_items/new.html.erb:7:in `_app_views_order_items_new_html_erb__1443667659032443898_70275798467060'
app/controllers/order_items_controller.rb:78:in `block (2 levels) in add_participants'
app/controllers/order_items_controller.rb:71:in `add_participants'
路线
post '/add_participants', to: 'order_items#add_participants'
提交表单
<%= form_for @new_oi, :url => {:action => "add_participants"}, method: :post, :html => { :id => "add_participants", :class => "add_participants" } do |f| %>
控制器操作
*line 71* def add_participants
@original_oi = OrderItem.find_by_id(session[:current_order_item_id].to_i)
@order = @original_oi.order
@new_oi = OrderItem.new(order_item_params)
respond_to do |format|
if @new_oi.save
format.html { redirect_to change_confirmation_path }
format.json { render action: 'show', status: :created, location: @new_oi }
else
*line 78* format.html { render action: 'new', notice: "We're sorry, but we were unable to complete this purchase." }
format.json { render json: @new_oi.errors, status: :unprocessable_entity }
end
end
end
提前致谢。
答案 0 :(得分:1)
想出来。我只需要更仔细地研究错误位置。记录未保存,因此add_participants操作尝试呈现新视图。