【发布时间】:2011-08-28 09:19:37
【问题描述】:
我正在进入 Rails 并尝试在此处的博客设置中添加“投票”功能:http://guides.rubyonrails.org/getting_started.html
在 app/controllers/posts_controller.rb 我创建了这个:
def incvotes
@post = Post.find(params[:id])
post.update_attributes(:upvotes => 1 )
format.html { redirect_to(@post, :notice => 'Vote counted.') }
format.xml { head :ok }
end
在 app/views/posts/index.html.erb 我创建了这个:
<%= link_to 'Vote', :controller => "posts", :action => "incvotes", :id => post.id %>
但是链接报错
没有路线匹配 {:controller=>"posts", :action=>"incvotes", :id=>1}
我在这里遗漏了一些东西,但不确定是什么。
耙路线:
incvotes_post POST /posts/:id/incvotes(.:format) {:action=>"incvotes", :controller=>"posts"}
posts GET /posts(.:format) {:action=>"index", :controller=>"posts"}
POST /posts(.:format) {:action=>"create", :controller=>"posts"}
new_post GET /posts/new(.:format) {:action=>"new", :controller=>"posts"}
edit_post GET /posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"}
post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"}
PUT /posts/:id(.:format) {:action=>"update", :controller=>"posts"}
DELETE /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"}
home_index GET /home/index(.:format) {:action=>"index", :controller=>"home"}
root /(.:format) {:action=>"index", :controller=>"home"}
【问题讨论】:
-
你的路由文件对帖子有什么看法?
标签: ruby-on-rails