简体   繁体   English

Rails 4.1变体不起作用

[英]Rails 4.1 Variants not working

I'm trying to use actionpack Variants in my rails 4.1 website. 我正在我的Rails 4.1网站上尝试使用actionpack Variants。

I'm following the rails guide, but it doesn't work. 我正在遵循rails指南,但是它不起作用。

In my application controller 在我的应用程序控制器中

before_action :set_request_variant

  private 

  def set_request_variant
    request.variant = :mobile if browser.mobile?
  end

I have Browser gem, and with iPhone user agent it return true so everything here is ok. 我有Browser gem,并且有了iPhone用户代理,它返回true,所以这里的一切都可以。

In my controller 在我的控制器中

  def show
    @event = Event.find params[:id]
    respond_to do |format|
      format.html
      format.html.mobile 
    end
  end

I have an application+mobile.html.haml and a _header+mobile.html.haml but the server serves always the standard layout and standards views... 我有一个application+mobile.html.haml_header+mobile.html.haml但是服务器始终提供标准布局和标准视图...

Any idea? 任何想法?

I think your layout and view template names might be the problem. 我认为您的布局和视图模板名称可能是问题。 Does it work if you try application.html+phone.haml and _header.html+mobile.haml instead? 如果您尝试改用application.html+phone.haml_header.html+mobile.haml是否可以使用?

The format I've suggested is consistent with the Rails 4.1 release notes here . 我建议的格式与此处的Rails 4.1发行说明一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM