intro_coder intro_coder - 6 months ago 8x
Ruby Question

set likes based on 2 parameters

I'm working on a project which should be able to put likes on it... one from each user that log into the page. I'm using ruby, active record and sinatra.

post '/like/:isbn' do
if favourite = Favourite.find_by(book_id: params[:book_id])
redirect to "/info/#{ params[:isbn] }"
favourite =
favourite.book_id = params[:book_id]
favourite.user_id =
redirect to "/info/#{ params[:isbn] }"

what I'm trying to do is searching for this favourite
where my book_id = book_id && user_id = user_id
... but I can't think of a way of putting it into ruby code....

Ccr Ccr

why don't you try this

Favourite.where(:my_book_id=> book_id , :user_id=> user_id)

this will return the array of favourite which has both :my_boo_id = book_id and :user_id = user_id