开发者

Accessing Subdomain in Rails3 model

开发者 https://www.devze.com 2023-02-20 10:40 出处:网络
I\'m working to get into my model a request for the subdomain. So basically I have a habtm association, which I need to ask, if my subdomain is found in the association.

I'm working to get into my model a request for the subdomain.

So basically I have a habtm association, which I need to ask, if my subdomain is found in the association. So in the user model -

def subdomain
  "subdomain"
end

def owner
   self.accounts.find_by_subdomain(subdomain)
开发者_JAVA百科end

If it is found, then I have permission to do stuff as the subdomain owner. But no matter how I can't figure out how to have the model access the subdomain

So basically I'm not sure how to pull "subdomain" from the controller / URI into the model. Thanks!


In your controller (or views for that matter) you can use something like request.host.split('.')[0] to get the host and parse out the subdomain.

0

精彩评论

暂无评论...
验证码 换一张
取 消