Create application for two different profiles

Asked

Viewed 403 times

-1

I am working on an application that has two different types of profiles and I want to find the best way to structure my application being that:

  1. All Urls in my app will start with one of the two profiles. Eg: (root/person_physical, root/person_legal);

  2. Many actions/screens will be shared by the two profiles, and some of these screens will have different behaviors for each profile, but others will not have differences. (Ex.: root/profile/about, root/profile/contact_form);

  3. I will have files that will be rendered on all screens of one profile, and other files in the other profile. (Ex.: personal header_physical, personal header_legal);

Does anyone have any tips to indicate?

  • Let me get this straight: A system user can be registered as PF or PJ, and will use different routes according to the type of person. Is that it? Or all users will have access to all routes?

  • For some static pages, all users have access to both routes, even when they are not registered. But some pages are only for logged in and certain profile users.

1 answer

1

Let’s say you have it on your table usuarios a column called tipo_pessoa, that accepts the values F or J.

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 of the legal person type.

If you want you can restrict the check to only or except 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 the routes, what you seek is the 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 don’t know if it will work. I’d rather not use, I think it’s best to just filter with before_action as shown above.

  • The problem is that I really need some controllers to be common to both types of people

  • @Rubyjuniordev And the before_action does not solve your problem? You can allow for everyone too, just do not use it on that specific controller.

  • i still need to access the standard functionalities always within or from the natural person or legal person...

  • @Rubyjuniordev I can’t understand you...

  • what I wanted was to have the Aboutcontroller controller, for example, and access it with both /pf/about and /pj/about. But I’ve already decided to do otherwise that met my original need. Thank you

  • @Rubyjuniordev If any other solution has served you, nay accept my answer as correct. Instead, create an answer with the solution and accept it as correct.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.