Hi Guys,
ActiveRecord is great for being able to drill down through many tables.
I often locate the very “top” record, and have a render :action =>
“show” display that top record.
Often I want to drill down like:
@kingdom.phylums.classes.orders.each do |order|
render :partial => “order/show”
end
But, depending on the user who is logged in, they see a different set of
“order”, or a different set of “phylums”.
In other words, as I drill down, I want to filter what the result set
(has_many) by data not in the ActiveRecord. I want to filter by data
that is from a web form, from ajax, or from session variables.
ActiveRecord makes it easy enough to do so with data in the record such
as:
has_many :phylums, :finder_sql => "blah blah blah where kingdom_id =
#{id} "
But it can’t do something like
has_many :authorized_orders, :conditions => “order_owned_by =
session[:current_user]”
I tried to get around this by thinking of:
render :partial => “call another action”
But render to my knowledge can’t really go calling another
ActionController to render more data.
So I’m kind of stuck… there’s no easy way to filter by external data,
and there’s no easy way to break out of an ActionView and include output
from an ActionController.
I don’t want to go totally breaking this “MVC” idea by throwing in nasty
sql everywhere.
Anyone around can give me a few pointers? Many thanks!