From: reuben doetsch Date: 2008-08-06T00:53:17+09:00 Subject: Re: Problem linking tables and accessing relationship heirarchy ------=_Part_6952_8287525.1217951689514 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline try this in the rails forum On Tue, Aug 5, 2008 at 10:49 AM, Brian Anderson wrote: > I'm not quite understanding this relationship thing between models and > tables. What I am trying to do within my view is get the price > information > by referring to it like this: > > <%= @item.itemprice.Qty1 %> > > In each of my individual views for the item_master table and the > itemprice > table I can get the info directly, but I can't figure out how to access > the > price that corresponds to the item. > > Here is my item.rhtml view test page: > > ------------------------- > > Note: this works > > <%= @item.itemDescription %> > > This does not > > <%= @item.itemprice.Qty1 %> > > > Below is all my Information: > > My Models: > > > ---------------------------- > > item_master.rb > > class ItemMaster < ActiveRecord::Base > has_many :itemprices > has_many :item_sub_prices > has_many :item_price_specials > end > > > ---------------------------- > > itemprice.rb > > > class itemprice < ActiveRecord::Base > belongs_to :item_master > end > > > My Controllers: > > ---------------------------- > > item_master_controller.rb > > class ItemMasterController < ApplicationController > > def show_all > @items = ItemMaster.find(:all) > end > > def item > @item = ItemMaster.find(params[:id]) > end > end > > > ----------------------------- > > itemprice_controller.rb > > > class ItemPriceController < ApplicationController > def show > @price = itemprice.find(params[:id]) > end > end > > > ----------------------------- > > Thanks, > > Brian > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_6952_8287525.1217951689514--