Rails 3, changing a specific value in a row

Posted by Elliot on Stack Overflow See other posts from Stack Overflow or by Elliot
Published on 2010-12-29T03:39:33Z Indexed on 2010/12/29 3:53 UTC
Read the original article Hit count: 479

Hey Guys,

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'

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby