I get into Rails and try to add a voting feature to my blog setup from here: http://guides.rubyonrails.org/getting_started.html
In app / controller / posts_controller.rb I created this:
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
In app / views / posts / index.html.erb I created this:
<%= link_to 'Vote', :controller => "posts", :action => "incvotes", :id => post.id %>
But the link gives an error
There are no route matches {: controller => "posts" ,: action => "incvotes" ,: id => 1}
Something is missing for me, but I don’t know what.
rake routes:
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"}
Zeno source
share