i'm working on the new ability on my RoR application. I've implemented the like/dislike system and now i'd like to add the ability to like the post just one time( User 1 can like or dislike the Post 2 just one time). How can i make this. I thought, that i can make it just like this
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# validates :avatar, attachment_presence: true
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
has_and_belongs_to_many :posts
def admin?
admin
end
end
class Post < ActiveRecord::Base
has_and_belongs_to_many :users
end
but besides of that i need one more field this has_and_belongs_to_many model, which will be the boolean field, that tells me if true - it is liked, false - it is disliked. BUt how can i access this field in this model. i do not have any idea ? Could you help me ?
Aucun commentaire:
Enregistrer un commentaire