我正在开发一个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' %>
可能是什么问题?
这是我的rake 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)))
答案 0 :(得分:1)
@mad_programmer - 请像您建议的那样在resources :pages
文件中添加routes.rb
。