form that causes the problem:
<%= form_for Like.find(post.user.likes), :html => { :method => :delete , :class => "unlike_post_like_form" } do |f| %>
Post model
belongs_to :user
has_many :likes
User model
has_many :posts
has_many :likes
Like model
belongs_to :post
belongs_to :user
i keep getting the following error:
TypeError in Users#show
Cannot visit Like
on
Like.find(post.user.likes),
EDIT:
First solution:
changing
Like.find(post.user.likes),
to
Like.find(post.user.likes).limit(1),
Second solution:
changing
Like.find(post.user.likes),
to
current_user.likes.where(:post_id => post.post_id)
Like.find(post.user.likes)is attempting to find aLikegiven an array oflikes. That doesn’t really make much sense.Most likely, you’ll want to search
post.user.likes, but even then, I’m a bit confused – you’ll need to post more code.Like.findis looking for either an id (integer), or a hash containing keys and values. An array doesn’t give it any information to search.EDIT: If you’re looking for the likes of current user. You’ll need to do the following…
current_user.likes.where(:post => @post)