Buying book from library

hi i’m very new to ROR.
i must do a basic library system its my homework.
i have models, user.rb (created by restful_authentication plugin) and
book.rb (created by scaffolding)
controllers: sessions_controller and users_controller(created by
restful_authentication plugin) and books_controller(created by
scaffolding)

user.rb,sessions_controller,users controller have the same codes
restful_authentication screencast and its working correct
******

and i want to have a buy link at books page
for example i login as ‘Jack’
when i login i’m showing the books page its OK. but also i wanna see
buy link and when i click it and return to the books page i wanna see
the books Jack bought
then logut and login again as’michael ’ i wanna see books page and
idont wanna see jack’s book i just wanna see michael’s book
how can i do it?
here is my books_controller.rb
i wanna have an buy action here(user will buy a book)

class BooksController < ApplicationController

GET /books

GET /books.xml

def index
@books = Book.all

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @books }
end

end

GET /books/1

GET /books/1.xml

def show

@book = Book.find(params[:id])
respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @book }
end

end

GET /books/new

GET /books/new.xml

def new
@book = Book.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @book }
end
end

GET /books/1/edit

def edit
@book = Book.find(params[:id])
end

POST /books

POST /books.xml

def create
@book = Book.new(params[:book])
respond_to do |format|
if @book.save
flash[:notice] = ‘Book was successfully created.’
format.html { redirect_to(@book) }
format.xml { render :xml => @book, :status => :created,
:location => @book }
else
format.html { render :action => “new” }
format.xml { render :xml => @book.errors, :status =>
:unprocessable_entity }
end
end
end

PUT /books/1

PUT /books/1.xml

def update
@book = Book.find(params[:id])
respond_to do |format|
if @book.update_attributes(params[:book])
flash[:notice] = ‘Book was successfully updated.’
format.html { redirect_to(@book) }
format.xml { head :ok }
else
format.html { render :action => “edit” }
format.xml { render :xml => @book.errors, :status =>
:unprocessable_entity }
end
end
end

DELETE /books/1

DELETE /books/1.xml

def destroy
@book = Book.find(params[:id])
@book.destroy
respond_to do |format|
format.html { redirect_to(books_url) }
format.xml { head :ok }
end
end
end
and here is my index.html.erb
i wanna see buy link and also see which book user bought

<Welcome <%=current_user.login %> ><%= link_to
“logout”, logout_path %>

Listing books

<% @books.each do |book| %>
<td><%= link_to 'Show', book %></td>
<td><%= link_to 'Edit', edit_book_path(book) %></td>
<td><%= link_to 'Destroy', book, :confirm => 'Are you sure?',

:method => :delete %>

<% end %>
Name
<%=h book.name %>

<%= link_to 'New book', new_book_path %> can anyone help? thanks

Ali Okur wrote:

Forget all that code and get a piece of paper.

Draw out your data model (you need Users, Books, something to track
which books a user bought, and maybe some other models). That will lead
you to what migrations, models, controllers, forms and specific actions
you need to create in your application.

Advice is free, responses to technical questions are free, the actual
homework is yours to do.

Ar Chron wrote:

Ali Okur wrote:

Forget all that code and get a piece of paper.

Draw out your data model (you need Users, Books, something to track
which books a user bought, and maybe some other models). That will lead
you to what migrations, models, controllers, forms and specific actions
you need to create in your application.

Advice is free, responses to technical questions are free, the actual
homework is yours to do.

okay.
but it’s not my homework
its about my homework but homework is more complex then it.it’s just a
simple program i wanna practise myself and i just wonder how i will make
user based action.

i add these codes to my program

****books_controller action
def buy
@book = Book.find(params[:id])
@book.user = current_user
end

****routes.rb
map.resources :books, :collection => { :buy => :get }

****books_ index.html.erb
<%= link_to ‘buy’, buy_book_path(book) %>

but when i am logging to books_index page

NoMethodError in Books#index
undefined method `buy_book_path’ for #ActionView::Base:0x64a45b0
why i’m getting this error?

Patience grasshopper… you’re trying to put the roof on the house when
the foundation is not laid yet.

Where are you storing the information about who purchased which book?

To see what you’ve created with your changes to routes.rb, at the OS
prompt, try:

rake routes >routes.lst

Then peruse that routes.lst file. You’ll see all the paths that are
available. Perhaps you don’t have what you think you have…