我進入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