我进入Rails和尝试在博客设置从这里添加一个“投票”功能:http://guides.rubyonrails.org/getting_started.htmlRuby on Rails的:行动的link_to,没有路由匹配
在应用程序/控制器/ 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
在应用程序/视图/职位/ index.html.erb我创造了这个:
<%= link_to 'Vote', :controller => "posts", :action => "incvotes", :id => post.id %>
但链接是给错误
No route matches {: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"}
什么是你的路由文件说有关的职位? – sscirrus 2011-05-18 20:49:08
资源:帖子 – Zeno 2011-05-18 20:55:09