1

Is it possible to use the thumbs_up gem without having users log in? Basically, I want anyone to vote for stuff without having to log in, like http://www.yourather.com .

Lastly, I get a routing error message when I try to to vote on a comment, samething happens when voting on an article.

No route matches [GET] "/comments/1/vote_up"

Model:

class Comment < ActiveRecord::Base
  acts_as_voteable
end

class Article < ActiveRecord::Base
  acts_as_voteable
end

View:

<%= link_to image_tag("up_arrow.jpeg"), vote_up_comment_path(@comment), 
    :method => 'post' %></br>
<%= link_to image_tag("down_arrow.jpeg"), vote_down_comment_path(@comment), 
    :method => 'post' %></br>

Controller:

def vote_up
  begin
    vote_for(@comment = Comment.find(params[:id]))
    render :nothing => true, :status => 200
  rescue ActiveRecord::RecordInvalid
    render :nothing => true, :status => 404
  end
end

def vote_down
  begin
    vote_against(@comment = Comment.find(params[:id]))
    render :nothing => true, :status => 200
  rescue ActiveRecord::RecordInvalid
    render :nothing => true, :status => 404
  end
end

Routes.rb:

resources :comments do
  member do
    post :vote_up
    post :vote_down
  end
end

resources :articles do
  member do
    post :vote_up
    post :vote_down
  end
end

Rake Routes (relevant part):

vote_up_comment   POST    /comments/:id/vote_up(.:format)      comments#vote_up
vote_down_comment POST    /comments/:id/vote_down(.:format)    comments#vote_down
comments          GET     /comments(.:format)                  comments#index
                  POST    /comments(.:format)                  comments#create
new_comment       GET     /comments/new(.:format)              comments#new
edit_comment      GET     /comments/:id/edit(.:format)         comments#edit
comment           GET     /comments/:id(.:format)              comments#show
                  PUT     /comments/:id(.:format)              comments#update
                  DELETE  /comments/:id(.:format)              comments#destroy
vote_up_article   POST    /articles/:id/vote_up(.:format)      articles#vote_up
vote_down_article POST    /articles/:id/vote_down(.:format)    articles#vote_down
articles          GET     /articles(.:format)                  articles#index
                  POST    /articles(.:format)                  articles#create
new_article       GET     /articles/new(.:format)              articles#new
edit_article      GET     /articles/:id/edit(.:format)         articles#edit
article           GET     /articles/:id(.:format)              articles#show
                  PUT     /articles/:id(.:format)              articles#update
                  DELETE  /articles/:id(.:format)              articles#destroy
root                      /                                    voteables#index
                          /comment/:id(.:format)               comments#show
                          /article/:id(.:format)               articles#show

I've looked at Clarification on how to use "thumbs_up" voting gem with Rails 3 and other related questions, but I can't make it work. Thanks

Community
  • 1
  • 1
user1352544
  • 53
  • 1
  • 5

1 Answers1

1

The docs on link_to says that the :method option should be a symbol. Try changing the view from:

<%= link_to image_tag("up_arrow.jpeg"), vote_up_comment_path(@comment), 
:method => 'post' %></br>

to

<%= link_to image_tag("up_arrow.jpeg"), vote_up_comment_path(@comment), 
:method => :post %></br>
EricM
  • 754
  • 1
  • 5
  • 16