Reputation: 359
I have installed the act_as_votable gem and followed the instructions by adding the gem to my gemfile,db migrate, added 'act as votable' to models and added methods in controller.
I have also updated my index page to show the buttons however I get this error message when I load my page:
undefined local variable or method `act_as_votable' for User (call 'User.connection' to establish a connection):Class
Ive never seen this error before, i'm new to ruby...
here is my repo for ease of understanding: https://github.com/Angela-Inniss/hair-do
User model:
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many :comments
has_many :hairstyles
has_many :saved_hairstyles
act_as_votable
end
hairstyle model:
class Hairstyle < ApplicationRecord
belongs_to :user, optional: true
has_many :comments, dependent: :destroy
validates :name, presence: true
validates :description, presence: true
validates :category, presence: true
act_as_votable
mount_uploader :photo, PhotoUploader
end
hairstyle controller:
def upvote
@hairstyle = Hairstyle.find(params[:id])
@hairstyle.upvote_from current_user
redirect_to hairstyles_path
end
def downvote
@hairstyle = Hairstyle.find(params[:id])
@hairstyle.downvote_from current_user
redirect_to hairstyles_path
end
index.html.erb:
<%= link_to like_hairstyle_path(hairstyle), class: 'like' method: :put do %>
<i class="fa fa-heart">
<span><%= hairstyle.get_upvotes.size %><span>
</i>
<%end %>
<!--this is a link block- create the block and then add elements inside?-->
<%= link_to like_hairstyle_path(hairstyle), class: 'like' method: :put do %>
<i class="fa fa-heart">
<span><%= hairstyle.get_downvotes.size %><span>
</i>
<%end %>
Upvotes: 0
Views: 455
Reputation: 20263
Notice what the error message says?
undefined local variable or method 'act_as_votable' for User (call 'User.connection' to establish a connection):Class
^^^^^^^^^^^^^^
It should be:
acts_as_votable
not:
act_as_votable
(You have it wrong in both User
and Hairstyle
.)
Upvotes: 1