Create application for two different profiles

-1

I'm working on an application that has two different types of profiles and I want to find the best way to structure my application, which is:

  • All URLs in my app will start with one of two profiles. Ex: (root / physical_person, root / legal_person);

  • Many actions / screens will be shared by both profiles, and some of these screens will have different behaviors for each profile, but in others they will have no differences. (Eg root / profile / about, root / profile / contact_form);

  • I will have files that will be rendered on all the screens of a profile, and other files in the other profile. (Eg header_people, header_people);

  • Does anyone have any tips to indicate?

        
    asked by anonymous 02.09.2014 / 03:12

    1 answer

    1

    Let's say you have in your table usuarios a column called tipo_pessoa , which accepts the F or J values.

    If you want to restrict all actions of a controller to one or another type of person, do so:

    class MeuController < ApplicationController
      before_action :somente_pessoa_fisica
    
      private
        def somente_pessoa_fisica
          redirect_to root_path if current_usuario.tipo_pessoa === "J"
        end
    end
    

    The above event will redirect the user to root if it is legal entity type.

    If you want you can restrict the scan to only or some methods:

    before_action :somente_pessoa_juridica, only: [:new, :create] # apenas new e create
    before_action :somente_pessoa_juridica, except: [:new, :create] # exceto new e create
    

    For routes, what you are looking for is namespace :

    namespace :pessoa_fisica do
      resources :foo
    end
    
    namespace :pessoa_juridica do
      resources :bar
    end
    

    But if a controller should be accessible in more than one namespace, I do not know if it will work. I would prefer not to use it, I think it's best to only filter with before_action as I showed above.

        
    02.09.2014 / 17:41