On Dec 1, 7:27 pm, Wayne M <[EMAIL PROTECTED]> wrote:
>
> But that seems rather unweildy.  This is a critical business
> requirement since we want to create different stores with their own
> unique look and feel, but the actual data displayed comes from one
> master database and needs to be filtered appropriately based on the
> store the user is browsing.
>
Just the first thing that springs to mind.

in your product class do

named_scope :green, ...
named_scope :recycled, ...

def self.scope_for_subdomain(subdomain)
  send case subdomain
  when 'green' then :green
  when 'recycled' then :recycled
  else
    :all
  end
end

and then your index action is

Product.scope_for_subdomain(request.subdomains.first).find :all
You could also just use anonymous scopes

Depending on what's in your app it might be better to pull the
selecting of the scope out into a before filter.

> Another critical requirement we have is that each individual product
> can have up to four prices, and the price is chosen based on the
> "store" the user is viewing it on (e.g. Product A is $15.00 on the
> mysite.com, but $12.00 on furniture.mysite.com).  I'm not sure what
> the best way to tackle that problem would be.
>
Again a random thought: products have a base price, and you have a
price_overrides table (products has_many price_overrides etc...)
Assuming you have Store objects describing the stores and a filter
that sets the current store you could have a method in your product
class similar to

def overriden_price(store)
  override = price_overrides.find_by_store_id store
  override ? override.price : self.price
end

and when you want to display the price to a user you just do

product.overriden_price(@current_store)

Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to