我使用的代码来自: http ://scottwb.com/blog/2012/02/23/a-better-way-to-add-mobile-pages-to-a-rails-site/
def check_for_mobile
session[:mobile_override] = params[:_mobile] if params[:_mobile]
prepare_for_mobile if mobile_device?
end
def prepare_for_mobile
prepend_view_path Rails.root + 'app' + 'views_mobile'
end
def mobile_device?
if session[:mobile_override]
session[:mobile_override] == "1"
else
# Season this regexp to taste. I prefer to treat iPad as non-_mobile.
(request.user_agent =~ /Mobile|webOS/) && (request.user_agent !~ /iPad/)
end
end
helper_method :mobile_device?
这很棒并且工作正常,但是我将如何更改视图名称而不是视图路径?这是个人喜好,但我宁愿拥有这样的移动视图:
/app/views/users/index_mobile.html.erb 与 /app/views_mobile/users/index.html.erb
谢谢!