Вопрос

I installed the gem 'thumbs_up', '~> 0.6.7' ran the necessary migrations per instructions and now having some issues getting this to function properly. Thanks for bearing with me as I am new with RoR. I'm running rails 4.0.0. and building a simple app where users upload images (pins) and I want the images to be voted on by other users. Problem I am having is that a logged in user is only able to vote on their own images, and not others. Also, once the vote_up or vote_against is clicked on in the view it does nothing, however the vote is being tallied, but the page and the flash notice are both not being rendered.

This is my models/users.rb:

class User < ActiveRecord::Base
  # some devise stuff here...
  acts_as_voter
end

models/pins.rb:

class Pin < ActiveRecord::Base
acts_as_voteable
end

My pins_controller:

def vote_up
    @pin = Pin.find(params[:id])
    current_user.vote_for(@pin)
    pin.update_vote_count
    render root_path
    flash[:success] = " You voted Up."
    respond_to do |format|
    format.js
  end
end

def vote_down
    @pin = Pin.find(params[:id])
    current_user.vote_against(@pin)
    @pin.update_vote_count
    respond_to do |format|
    format.js
    redirect_to pins_url, notice: 'You voted Down'
  end
end

This is my view:

 <strong><%= pin.plusminus %></strong><br/>
          <%= link_to "Up Vote", vote_up_pin_path(pin), :method => :post, :remote => true, :class=>'up-vote' %> |
          <%= link_to "Down Vote", vote_down_pin_path(pin), :method => :post, :remote => true, :class=>'down-vote' %>

And here is my routes.rb:

resources :pins do
member do
  post :vote_up
  post :vote_down
  post :unvote
  end
end

Any help would be very much appreciated, thanks in advance!

Это было полезно?

Решение

Resolved my issue. Was a rookie mistake in that for any user to see the vote option I put the end tag after the option to vote in my view.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top