ruby on rails - acts_as_votalble always shows link to dislike -


i'm trying use acts_as_votable in rails application. have link allow users or unlike post. right shows link dislike ( current_user has liked status). case when seed database.

app/controllers/status_controller.rb

class statuscontroller < applicationcontroller   before_action :set_status    def     current_user.liked_by @status     respond_to |format|       format.js {render inline: "location.reload();" }     end   end    def dislike     current_user.unliked_by @status     respond_to |format|       format.js {render inline: "location.reload();" }     end   end    private    def set_status     @status = status.find(params[:id])   end 

app/models/user.rb

class user < activerecord::base   # include default devise modules. others available are:   # :timeoutable , :omniauthable   devise :database_authenticatable, :registerable, :confirmable, :lockable,          :recoverable, :rememberable, :trackable, :validatable   has_many :statuses, dependent: :destroy   mount_uploader :images, imageuploader   mount_uploader :avatar, avataruploader   acts_as_voter    def age     time.now.year - birth_date.year   end    def name     "#{first_name} #{last_name}".titleize   end end 

app/models/status.rb

class status < activerecord::base   acts_as_votable   belongs_to :user end 

app/views/welcome/home.html.slim

- @statuses.each |status|   .chip     = cl_image_tag status.user.avatar.full_public_id, alt: status.user.name     = " #{status.user.name} #{status.user.age}, #{status.user.city}, #{status.user.state}"   p     = status[:message]   p     - if current_user.voted_up_on? status       = link_to dislike_status_path(status), method: :post, remote: true         i.small.material-icons.blue-text           | thumb_up     - else       = link_to like_status_path(status), method: :post, remote: true          i.small.material-icons.grey-text           | thumb_up     = time_ago(status.created_at) 

it seems like/unlike wrong way

  def     current_user.liked_by @status 

and

  def dislike     current_user.unliked_by @status 

but have write @status.liked_by current_user , @status.unliked_by current_user

check documentation , examples:

@post.liked_by @user1 @post.unliked_by @user1 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -