Rails 3 将子资源映射到带有子域的根
我有一个如下所示的网站模型:
class Site < ActiveRecord::Base
has_one :resource_1
has_one :resource_2
has_one :resource_3
has_many :resource_4
end
我已按照 http://asciicasts.com/episodes/221-subdomains-in-rails-3。这样,如果我访问 http://subdomain.myapp.com 它会按名称找到该网站(假设子域是站点名称)并通常在 /sites/:id/resource_1 处显示页面。
我仍然可以从那里访问网站的所有其他子资源,但我得到的网址看起来像 http://subdomain.myapp.com/sites/:id/resource_name/:resource_id 我希望能够设置类似于 http://subdomain.myapp.com/resource_name/:resource_id。
我确信正确的术语只是逃避了它,但没有真正简洁地描述它的语言使得谷歌搜索解决方案徒劳无功。任何和所有回复表示赞赏!
谢谢!
I've got a model for sites that looks like:
class Site < ActiveRecord::Base
has_one :resource_1
has_one :resource_2
has_one :resource_3
has_many :resource_4
end
I've got subdomains set up following the method outlined in http://asciicasts.com/episodes/221-subdomains-in-rails-3. So that if I visit http://subdomain.myapp.com it finds the site by name (assuming subdomain is the site's name) and displays the page normally at /sites/:id/resource_1.
I can still access all the other sub-resources of site from there, but I get a url that looks like http://subdomain.myapp.com/sites/:id/resource_name/:resource_id and I'd like to be able to set up routes that look like http://subdomain.myapp.com/resource_name/:resource_id.
I'm sure the proper terminology is just escaping it, but not really having the language to describe it concisely has made googling for a solution unfruitful. Any and all replies are appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
向应用程序控制器添加了一种通过子域获取站点的方法,然后使用要求站点存在的浅层路由。
Added a method to the application controller to get site by subdomain, then used shallow routing requiring site to be present.