2012-02-09 39 views
0

我正在開發一個rails應用程序,並且有一個名爲ned內頁控制器的方法。我想顯示 form_for(@pages) 但它給我這個錯誤:未定義的方法在視圖中的錯誤

`NoMethodError in Pages#new 

Showing C:/rorapp/app/views/pages/_form.html.erb where line #1 raised: 

undefined method `pages_path' for #<#<Class:0x5a8d840>:0x5a8a558> 
Extracted source (around line #1): 

1: <%= form_for(@pages) do |f| %> 
2: 
3: <% end %> 
Trace of template inclusion: app/views/pages/new.html.erb 

Rails.root: C:/rorapp 

Application Trace | Framework Trace | Full Trace 
app/views/pages/_form.html.erb:1:in `_app_views_pages__form_html_erb__975660997_47429844' 
app/views/pages/new.html.erb:2:in `_app_views_pages_new_html_erb___256256638_47474016' 
app/controllers/pages_controller.rb:11:in `new'` 

這裏是頁控制器我控制器的方法:

def new 
    @pages = Page.new 

    respond_to do |format| 
    format.html # new.html.erb 
    format.json { render :json => @post } 
    end 
    end 

下面是部分表單視圖_form.html.erb:

<%= form_for(@pages) do |f| %> 

<% end %> 

,這裏是我如何在new.html.erb視圖中使用它: <%= render 'form' %> 可能是什麼問題?

編輯-1

這裏是我的耙routes命令輸出:

home_index GET /home/index(.:format)  {:controller=>"home", :action=>"index"} 
home_search POST /home/search(.:format)  {:controller=>"home", :action=>"search"} 
home__help GET /home/_help(.:format)  {:controller=>"home", :action=>"_help"} 
home_create GET /home/create(.:format)  {:controller=>"home", :action=>"create"} 
pages_index GET /pages/index(.:format)  {:controller=>"pages", :action=>"index"} 
pages_new GET /pages/new(.:format)  {:controller=>"pages", :action=>"new"} 
      POST /pages/new(.:format)  {:controller=>"pages", :action=>"new"} 
pages_edit POST /pages/edit(.:format)  {:controller=>"pages", :action=>"edit"} 
      GET /pages/edit(.:format)  {:controller=>"pages", :action=>"edit"} 
root   /      {:controller=>"home", :action=>"index"} 
       /:controller(/:action(/:id(.:format))) 
+1

請在終端 – 2012-02-09 22:27:30

+1

上發佈您的'routes.rb'文件或輸出'rake routes'命令,問題是找不到路由。發佈您的routes.rb文件 – apneadiving 2012-02-09 22:27:47

+0

我已經在編輯中給出了我的routes.db。 – Maverick 2012-02-09 22:34:32

回答

1

@mad_programmer - 請您routes.rb文件中添加resources :pages喜歡別人建議。