ruby-on-rails – 在Rails中,如何制作:移动视图在未找到时回退
这个问题是我之前未回答的问题的后续问题:
ActionView::MissingTemplate: Missing template (Trying to render nonexistent :mobile format )
由于似乎没有与Rails方法达成共识,有什么方法可以从移动设备访问以呈现默认值:html何时:移动格式不可用? (如果a:移动视图存在,则应优先于未移动格式的移动视图). 解决方法
假设你有一个mobile_request?控制器实例方法来检测移动请求,那么你应该能够设置格式回退链:
# application_controller.rb before_filter :set_request_format,:set_format_fallbacks respond_to :html,:mobile # etc def set_request_format request.format = :mobile if mobile_request? end def set_format_fallbacks if request.format == :mobile self.formats = [:mobile,:html] end end 这应该工作,但显然它并不完全. 希望它会以某种方式修复. 还看看: Can a mobile mime type fall back to “html” in Rails? Changing view formats in rails 3.1 (delivering mobile html formats,fallback on normal html) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |