2014-04-11 65 views
0

我有一个表单在'order_items'控制器上提交自定义操作'add_participants'。它似乎提交了正确的操作,但错误引用了与'order_items#new'关联的无关视图Rails:形成错误视图的路径

我已经试过包括:

  • 改变从 'add_participants' 的路线描述为 '/ add_participants',反之亦然。
  • 在'order_items'文件夹中创建特定的'add_participants.html.erb'文件。
  • 从<%=的form_for @new_oi ...%>到<%=的form_for OrderItem.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 

在此先感谢。

回答

1

想通了。我只需要更仔细地研究错误位置。该记录没有保存,所以add_participants操作正试图呈现新视图。

+0

而你刚刚在控制器或'form_for'中更改了url? –

+0

我改变了控制器第78行中的渲染动作。 – steel