Rails设计身份验证,排除登录屏幕布局

时间:2017-11-10 13:51:11

标签: ruby-on-rails devise

我正在使用设计验证。我希望登录页面出现在空白页面上。因此,渲染'布局/导航'....<%=渲染'布局/ Topnavbar'%> .....<%=渲染'布局/页脚'%>我不希望看到这一点。我怎么能这样做?

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  ##    milia defines a default max_tenants, invalid_tenant exception 
   handling
  ##    but you can override these if you wish to handle directly
  rescue_from ::Milia::Control::MaxTenantExceeded, :with => :max_tenants
  rescue_from ::Milia::Control::InvalidTenantAccess, :with => :invalid_tenant


  before_action :authenticate_tenant!
end

application.html.erb

<div id="wrapper">    
  <!-- Navigation -->
  <%= render 'layouts/navigation' %>

  <!-- Page wraper -->
  <div id="page-wrapper" class="gray-bg">

      <!-- Page wrapper -->
      <%= render 'layouts/topnavbar' %>

      <!-- Main view  -->
      <p class="notice"><%= notice %></p>
      <%= yield %>

      <!-- Footer -->
      <%= render 'layouts/footer' %>

  </div>
  <!-- End page wrapper-->    

class UsersController < ApplicationController
before_action :authenticate_user!

def index                   
    @users = User.all
end

def show
    @user = User.find(params[:id])
end

def destroy
    user = User.find(params[:id])
    user.destroy
    redirect_to users_path, :notice => "User deleted"
end

def update
    @user = User.find(params[:id])

    if @user.update_attributes(secure_params)
        redirect_to user_path, :success => 'User updated'
    else
        redirect_to user_path :alert => 'Unable to update user'
    end
end

end

我理解......不幸的是它不起作用......我认为Milia gem文件不使用控件。我在路线中使用了Milia / sessions not desmeise / sessions。使用Milia成员和用户控件。渲染布局:false不起作用

resources :members
  get 'home/index'

  root :to => "home#index"


  # *MUST* come *BEFORE* devise's definitions (below)
  as :user do   
    match '/user/confirmation' => 'milia/confirmations#update', :via => :put, :as => :update_user_confirmation
  end


  devise_for :users, :controllers => { 
    :registrations => "milia/registrations",
    :confirmations => "milia/confirmations",
    :sessions => "milia/sessions", 
    :passwords => "milia/passwords", 
  }

2 个答案:

答案 0 :(得分:0)

完全禁用登录布局

在控制台中生成设计控制器

rails generate devise:controllers [scope]

render layout: false操作

结束时致电new

禁用布局内的特定部分,但保留基本布局

<%= render 'layouts/navigation' if controller_name != 'milia/sessions' || action_name != 'new' %>

最好把这个条件变成帮手

答案 1 :(得分:-2)

这对我有用。你认为它是一个整洁的代码?谢谢你的帮助。

<% if user_signed_in? %>
      <%= render 'layouts/navigation' %>

      <!-- Page wraper -->
      <div id="page-wrapper" class="gray-bg">

          <!-- Page wrapper -->
          <%= render 'layouts/topnavbar' %>

          <!-- Main view  -->          
          <%= yield %>

          <!-- Footer -->
          <%= render 'layouts/footer' %>

      </div>     
      <!-- End page wrapper--> 
    <% end %>
    <div class="gray-bg">
      <%= yield if controller_name != 'milia/sessions' && action_name == 'new' %>
    </div>
  </div>