Problem linking tables and accessing relationship heirarchy


B

Brian Anderson

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
 
Ad

Advertisements

R

reuben doetsch

[Note: parts of this message were removed to make it a legal post.]

try this in the rails forum
 

Top