2010-12-15 27 views
0

我想讓裏面的 '後視圖'的form_for問題

一個 '註釋' 的形式,但這種幫助不能工作

<%= form_for([@post, @comment]) do |f| %> 
    ... 
<% end %> 

RVM 1.9.2 軌3.0.3

編輯1: 錯誤:

undefined method `model_name' for NilClass:Class 

編輯2提取的源(左右線#23):

20: <% end %> 
21: </ul> 
22: 
23: <%= form_for [@list,@item] do |form| %> 
24:  
25: <%= form.text_field :due %> 
26: <p><%= form.text_field :title %> 

應用程序跟蹤

app/views/lists/show.html.erb:23:in `_app_views_lists_show_html_erb___3300490552675426158_2162821280_4216612080991561324' 
app/controllers/lists_controller.rb:22:in `show' 

信息名單| has_many項目。 item | belongs_to的列表

+0

你得到什麼樣的錯誤? – Trip 2010-12-15 05:00:44

+0

請你給我們更多的堆棧跟蹤。 – 2010-12-15 06:14:01

回答

3

看看這個工程

<% form_for @post, :url => { :action => "create" } do |post_form| %> 
    ... 
    <% post_form.fields_for :comments do |comment_fields| %> 
    Comment ID: <%= comment_fields.text_field :id %> 
    <% end %> 
<% end %> 

您可以檢查http://guides.rubyonrails.org/form_helpers.html(參見7.3節使用表單助手)

0

確定在這裏我做了什麼。

路線

resources :lists do 
    resources :items 
    end 

名單控制器

def show 
    @list = List.find(params[:id]) 
    @item = @list.items.new 


    respond_to do |format| 
     format.html # show.html.erb 
     format.xml { render :xml => @list } 
    end 
    end 

show.html.erb

<%= form_for([@list, @item]) do |form| %> 
<p><%= form.text_field :title %> 
<%= form.submit %></p> 
<% end %>