This question seems ridiculously easy, but I seem to be stuck.
Lets say we have a table “Books”
Each Book, has a name, description, and a status.
Lets say I want to create link in the show view, that when clicked, solely changes the status (to “read”) for example.
So far, I’ve tried adding a block in the controller, that says:
def read
@book = Book.find(params[:id])
@book.status = "Read"
@book.update_attributes(params[:book])
respond_to do |format|
format.html { redirect_to :back}
format.xml { render :xml => @book }
end
end
Then I’ve added a link to the view that is like:
<%= link_to “Read”, read_book_path(@book), :method => :put %>
This isn’t working at all. I have added it to my routes, but it doesn’t seem to matter.
Any help would be great! Thanks!
-Elliot
EDIT: Forgot to add I’m getting a NoMethodError: undefined method `read_book_path’
You need to define a method called read:
Then you want <%= link_to “Read”, read_book_path(@book), :remote => true %>
and in routes.rb:
Once that works, mess around with changing the method to :put