Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Problem linking tables and accessing relationship heirarchy
brian
8/5/2008 3:50:00 PM
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-...
.
1 Answer
reuben doetsch
8/5/2008 3:53:00 PM
0
[Note: parts of this message were removed to make it a legal post.]
try this in the rails forum
On Tue, Aug 5, 2008 at 10:49 AM, Brian Anderson <brian@arielpremium.com>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-...
.
>
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Problem linking tables and accessing relationship heirarchy
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password