On Feb 18, 2006, at 12:27 PM, James W. wrote:
what?? give an example.
also
“The Shop object is figured out at the beginning of each request by
looking at the incoming domain of the user.” has no example of how it
could be used.
I feel this is a very important aspect to rails that needs some futher
explanation.
What they are probably doing is getting the shop in a before_filter
using the subdomain. Something like this:
class ApplicationController < ActionController::Base
before_filter :setup_shop
attr_accessor:shop
protected
def setup_shop
if @shop = Shop.find_by_subdomain(request.subdomains.first)
else
@shop = Shop.find_by_subdomain("default")
end
end
end
This way on every request @shop will be set the the correct shop
according to the subdomain in the url like:
http://fooshop.example.com
So @shop will be the current shop account on every request and if the
request doesn’t have a subdomain it gets set tho the default shop.
Then you can scope your queries like in the blog article:
class Product < AR:B
def self.search(q)
find(:all, :conditions => “title LIKE ‘%#{q}%’”)
end
end
@shop.products.search(â??snowboardsâ?) will run this find query:
Product.find(:all, :conditions => [“title LIKE ? AND shop_id = ?”, “%#
{q}%”, 2]
The shop_id = 2 is added automatically by these scoped queries. So in
the above @shop.id would be 2 and the Product search is scoped to
that particular shop.
Hope that makes sense to you 
Cheers-
-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732