如何在轨道上隐藏部分视图。

时间:2015-11-12 10:15:57

标签: ruby-on-rails

在我的application.html.erb中,我正在渲染标题和导航栏

<script src="js/lib/require.js"></script>
<script>
    //Load common code that includes config, then load the app
    //logic for this page. Do the requirejs calls here instead of
    //a separate file so after a build there are only 2 HTTP
    //requests instead of three.
    requirejs(['./js/common'], function (common) {
        //js/common sets the baseUrl to be js/ so
        //can just ask for 'app/main1' here instead
        //of 'js/app/main1'
        requirejs(['app/main1']);
    });
</script>

在设计视图中,我想隐藏标题和导航栏,只显示登录视图。

2 个答案:

答案 0 :(得分:4)

你可以检查你的devise_controller:

<% unless devise_controller? %>
    <%= render 'layouts/header' %>
    <%= render 'layouts/navbar' %>
<% end %>
<%= yield %>

答案 1 :(得分:0)

As mentioned by marczking, you could use the devise_controller? command in the application layout, or you could create a totally different layout:

#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
   layout :auth, if: devise_controller?
end

--

display only the login view

If you only wanted to show the header on login, you may wish to use another devise helper - user_signed_in?:

<% unless user_signed_in? %>
   <%= render 'layouts/header' %>
<% end %>

This would show the header / nav when the user is not signed in.