【问题标题】:Choosing different layout file for sinatra-authentication为 sinatra 身份验证选择不同的布局文件
【发布时间】:2012-08-31 00:55:43
【问题描述】:

sinatra-authentication 期望 layout.haml 用于其预滚动的身份验证视图。

如何指定sinatra-authentication 可以使用的不同布局模板(例如auth_layout.haml),以便我可以保留layout.haml 以供我的应用查看?

我目前不理想的方法是:

  • 允许sinatra-authentication使用标准layout.haml
  • 在应用的所有其他部分显式使用另一个布局文件(例如std_layout.haml

例如

...
erb :home_page, :layout => :std_layout
...

我更喜欢反过来:)

【问题讨论】:

    标签: ruby authentication views sinatra haml


    【解决方案1】:

    您可以阅读on Layout Engines 或直接尝试:

    get '/login' do
      haml :login, layout: auth_layout
    end
    

    EDIT-1:你的评论是好的 layout: auth_layout 是 ruby​​ 1.9 语法 :layout => auth_layout 是 1.9 之前使用的语法

    如果你在谈论 this sinatra-authentication,你必须破解 this fileapp.get '/login/?' 方法关于 (Module::Helpers#use_layout?)。

    EDIT-2:我想覆盖 use_layout? 方法会对你有所帮助,也许类似于

    Module Sinatra
      Module Helpers
        def use_layout?
           request.xhr? ? false : :auth_layout
        end
      end
    end
    

    【讨论】:

    • 谢谢。上面的代码不起作用,因为在 sinatra-authentication 中调用了 login.haml。此外,layout: 语法似乎与 sinatrarb.com/blog 上的语法不匹配
    • 再次感谢@kfl62 :) 是的,我之前查看了源代码,但不知道如何更改代码以使用另一个布局文件。任何建议或代码都会很有帮助:)
    猜你喜欢
    • 2011-03-29
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    相关资源
    最近更新 更多