Learn something new every day.

If anyone else is wondering if that is slower or faster then
current_user.favorites.where(:post_id => @post.id).count == 1 the SQL
from the .exists? method is:

SELECT 1 FROM "favorites" WHERE "favorites"."post_id" = 666 AND
"favorites".user_id = 1 LIMIT 1



On May 17, 4:11 pm, Stefan Gelenchev <[email protected]> wrote:
> Played with the code for hours and just got it to work, 20 minutes after
> posting here. ruby-forum.com brought me luck, thank you :)
>
> Here the working code:
>
> <% if current_user.favourites.exists? :post_id => @post.id %>
>
> So it checks the favs of the current_user in the fawvourites table and
> compares the post_id ( which is the id of the already faved post) to the
> current post that is displayed on the page.
>
> Hope this helps someone else too :)
>
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to