Rails route to model instance - by domain name

▼魔方 西西 提交于 2019-12-04 16:44:44

Assuming each area has some sort of domain_name field, it seems like you should be able to do something like this:

class HotelsController < ApplicationController
  def index
    @hotels = Area.find_by_domain_name(request.subdomains.first).hotels
  end
end

You could even refactor it into a named_scope using a lambda if you like.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!