Doubt Gem Devise

0

Hello,

I'm using gem devise for a project of its own and a question has arisen, how do I leave just one free route, for example I want all other routes to need login and password minus the main page.

I did some research and got to this link but it did not work out.

Thank you

    
asked by anonymous 23.10.2017 / 02:48

2 answers

1

How about using it this way?

Considering that you want to allow non-authentication access only to the main application page:

  

application_controller.rb

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

  # Insira esta linha
  before_action :authenticate_user!
end
  

home_controller.rb

class HomeController < ApplicationController
  # Insira esta linha
  skip_before_action :authenticate_user!

  def index
  end
end

In this way, user authentication will be required on all controllers and their actions, except to the controller responsible for the main page of your application.

And if for some reason you want to limit yourself to the action "index" of the controller responsible for the main page of your application, you can do this:

skip_before_action :authenticate_user!, only: [:index]

I hope I understand your problem and have helped you solve it.

    
23.10.2017 / 04:12
1

How about doing something like this ...

How do you want to allow unauthenticated access to the main application page only:

This is how I like to set up my application

1) in the route file

  # config / routes.rb
  Rails.application.routes.draw do
    ide_for: users,: controllers => {registrações: 'users / registrations',
                                         sessões: 'usuários / sessões',
                                         senhas: 'usuários / senhas',
                                         confirmações: 'usuários / confirmações'
    }
    autenticar: o usuário faz
      namespace: os usuários fazem
        recursos: posts
        root: to => 'channels # index'
      fim
    fim
    recursos: contats
    match "/ about_us" => "pages # about_us",: as =>: about_us, via:: todos
    Páginas de raiz # índice '
  fim

In this way, all routes that are outside the namespace ** are public users

I also create a master user controller that the application controller extended as well

# app / controllers / user_controller.rb
classe UserController <ApplicationController
  before_filter: authenticate_user!
fim

Now for all device drivers

# app / controllers / users / registrations_controller.rb
Usuários da classe :: RegistrationsController <Devise :: RegistrationsController
  privado
  def after_sign_in_path_for (usuário)
    user_root_path
  fim
fim

The entire controller of my users extends my user controller

# app / controllers / users / posts_controller.rb
classe Usuários :: PostsController <UserController
  ...
fim

You can follow this format for all other drivers. If you still need help, let me know.

    
27.12.2017 / 06:41