开发者

Simple rails button question

Very noob question here.

I am trying to make a digg-like website and when they click a button I want a counter to go up, just like in digg. So I did:

 <%=button_to("vote", :action => "vote")%>

and then in my controller I made a action:

def vote
  @article = Article.find(params[:id])
  @article.votes = @article.votes + 1
  respond_to do |format|
    format.html { redirect_to(@article.company) }
  end
end

When I do that you I get the error:

No route matches 开发者_C百科{:action=>"agree", :controller=>"companies"}

What should I do?


In a terminal type "rake routes", then look at your routes to find what path you need to use to vote for an article.

Then use

<%= button_to "Vote", vote_path(:id => article.id) %>

Just change the "vote_path" to the path in your rake routes output.

If it's not already in your rake routes file, put something like this in

match "vote/:id" => "controler_name#vote", :as => :vote 


Take a look at http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜