我想知道是否有任何方法可以根据域名更改相同 Rails 应用程序的视图格式。
例如 :
- www.domain.com => respond_to format.html
- api.domain.com => respond_to format.xml 或 format.json
感谢你的帮助
是的,在控制器中使用 before_filter 并设置response.format
根据 的值request.host
.
class Controller < ActionController::Base
before_filter :adapt_response_format
protected
def adapt_response_format
response.format = case request.host
when "xml.foo.com" then :xml
else :html
end
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)