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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedAug 1, '12 at 3:55p
activeAug 1, '12 at 3:55p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Jean-Sébastien D.: 1 post

People

Translate

site design / logo © 2021 Grokbase