Hello all! I'm a newbie in rails, and I've been looking all over for an answer for this issue. Here's what I have:
class Item < ActiveRecord::Base
belongs_to :book
class Book < ActiveRecord::Base
has_many :items
Now I want to list all the items with their properties and the book associated with them. They would go under index in the items_controller.rb
class ItemsController < ApplicationController
# GET /items
# GET /items.xml
def index
@items = Item.all
now how would I handle books in the ItemsController so I can list them in index.html.erb keeping in mind that an item belongs to only one book? if I add:
@books = items.book.find
right under @items = Item.all so I can reference them in the index.html.erb I get:
undefined method 'book' for #<Array:0x10427f998
>
I have a feeling that the answer is so simple but so far I haven't figured it out. Is there any tutorial that you guys are aware of that covers this matter?
Thank you!