2014-04-11 63 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