Accessing Subdomain in Rails3 model
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.
精彩评论