I am trying to fetch the information from books associated with a
customer but seem that the middle association doesn't works

Here my model

Book
    has_many :book_managers
    has_many :customers, :through => :book_managers

Customer
    has_many :book_managers
        has_many :books, :through => :book_managers

Book_Manager
    belongs_to :customer
    belongs_to :book
The field are has follow

Book          Customer      book_manager
id            id            id
description   email         customer_id
              password      book_id
              first         visible
              last
When fetching the information in my def edit, the following is
successfull

@book = Book.first
@book = Book.last
The following seem to fails

@customer = Customer.find(params[:id])
@book = @customer.books.first
@book = @customer.books.order("created_at DESC").first
Is there something i miss?

I also try to verify by creating an index for book_manager controller
and view and nothing appears, its seems its empty. The way i created the
books was as follow

BookController

def create
@book = current_customer.books.build(params[:book])
    if @book.save
        flash[:success] = "Book Created"
        redirect_to root_url
    else
        render 'customer/edit'
    end
end

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to