How do i access the book id in like method from like_book_path(@book),:method=>:post .As you can see,this link is under the book loop.What do i need to do to make like_book_path(@book) carry the book_id and how would i access it in like action?
so far in the view i can get the id through book.id .Any help will be greately appreciated.
View:
<% @books.each do |book|%>
<%= book.name%>
<%= link_to "like this book", like_book_path(@book), :method => :post %>
<%end%>
Book controller:
def like
@book = Book.find(params[:id])
#other methods to facilitate like functionality
end
Route:
resources :book do
member do
post :like
end
end
I guess you should replace your loop with:
the difference is just to use
bookinstead of the non existing@book.