寻找action出错
本帖最后由 hjack 于 2010-04-29 20:57:42 编辑 有一个表叫news,
index页面有如下一行代码生成链接
<%= link_to 'new', new_news_path %>
点击这个代码生成的链接(http://localhost:3000/news/new),发生如下错误,看样子是去找到了show这个action。
Processing NewsController#new (for 127.0.0.1 at 2010-04-29 20:47:23) [GET]
[4;36;1mNews Columns (15.6ms)[0m [0;1mSHOW FIELDS FROM `news`[0m
Rendering template within layouts/news
Rendering news/new
ActionView::TemplateError (news_url failed to generate from {:controller=>"news", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["news", :id] - are they all satisfied?) on line #3 of app/views/news/new.html.erb:
1: <h1>New news</h1>
2:
3: <% form_for(@news) do |f| %>
4: <%= f.error_messages %>
5:
6: <p>
(eval):16:in `news_path'
app/views/news/new.html.erb:3
app/controllers/news_controller.rb:30:in `new'
Rendered rescues/_trace (109.2ms)
Rendered rescues/_request_and_response (0.0ms)
Rendering rescues/layout (internal_server_error)
map.resources :news,:singular => :new
或者在你的<% form_for @news do
[解决办法]
f
[解决办法]
%> 写明controller和action
<%form_for @news, :url => {:controller => "news", :action => "create"}
个人建议你换个表名称,比如articles