Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails & Devise: How to render login page without a layout?

I know this is probably a simple question, but I'm still trying to figure Devise out...

I want to render :layout => false on my login page; how can I do this with Devise?

like image 557
neezer Avatar asked Dec 10 '10 18:12

neezer


People also ask

What are Rails used for?

Rails is a development tool which gives web developers a framework, providing structure for all the code they write. The Rails framework helps developers to build websites and applications, because it abstracts and simplifies common repetitive tasks.

Is Rails a backend or frontend?

Ruby on Rails is used as a backend framework for web applications. It's known for efficiency and scalability. You can write rich functionality with much fewer lines of code as opposed to what you'd need in Java or Node.

Is Rails better than Django?

In the battle of Django vs Ruby on Rails performance, it is observed that Rails is faster by 0.7%. It is because Rails has the advantage of a rich repository of amazing libraries and plugins to enhance the speed and eventually the performance of this framework.

What is rail framework?

Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web pages. It encourages and facilitates the use of web standards such as JSON or XML for data transfer and HTML, CSS and JavaScript for user interfacing.

What is rails?

What's Rails? Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern. Understanding the MVC pattern is key to understanding Rails.

What is Ruby on rails?

Ruby on Rails makes it much easier and more fun. It includes everything you need to build fantastic applications, and you can learn it with the support of our large, friendly community . Latest version — Rails 6.0.3.2 released June 17, 2020

What is the rails full stack approach?

This version of Rails has been years in the conceptual making. It’s the fulfillment of a vision to present a truly full-stack approach to web development that tackles both the front- and back-end challenges with equal vigor.

What is a model in rails?

Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module. The View layer is composed of "templates" that are responsible for providing appropriate representations of your application's resources.


2 Answers

You can subclass the controller and configure the router to use that:

class SessionsController < Devise::SessionsController   layout false end 

And in config/routes.rb:

devise_for :users, :controllers => { :sessions => "sessions" } 

You need to move the session views to this controller too.

OR make a method in app/controllers/application_controller.rb:

class ApplicationController < ActionController::Base    layout :layout    private    def layout     # only turn it off for login pages:     is_a?(Devise::SessionsController) ? false : "application"     # or turn layout off for every devise controller:     devise_controller? && "application"   end  end 
like image 151
iain Avatar answered Sep 23 '22 06:09

iain


You can also create a sessions.html.erb file in app/views/layouts/devise. That layout will then be used for just the sign in screen.

like image 31
Paul Raupach Avatar answered Sep 26 '22 06:09

Paul Raupach