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
 
R

reuben doetsch

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

try this in the rails forum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top