routes matching different path for different users.

I want to display different layouts based on user.
If user is "intraOp" the I want to use layout intraOp, if user is
"interOp" I want to display layout interOp while if controller_devise
I want to display application layout.
I based the user selection on request.path.
If request.path is /intraOp then I select user IntraOp, if /interOp
then select user interOp and so on.
The routes.rb is:

match "intraOp" => "companies#index"
match "interOp" => "companies#index"

The problem is that I use pagination.
When the request.path is /interOp companies#index is launched, and are
displayed 10 companies with pagination.
When I click for displaying page 2 companies#index is launched but the
path is not /interOp/companies......... but is
/intraOp/companies.........that is because companies#index is first
matched with "intraOp".
Have you some suggestions to solve the problem to having different
layouts based on user?
I prefer to not create two controllers: intraOp and interOp.

I want to display different layouts based on user.
If user is "intraOp" the I want to use layout intraOp, if user is
"interOp" I want to display layout interOp while if controller_devise
I want to display application layout.
I based the user selection on request.path.
If request.path is /intraOp then I select user IntraOp, if /interOp
then select user interOp and so on.
The routes.rb is:

match "intraOp" => "companies#index"
match "interOp" => "companies#index"

The problem is that I use pagination.
When the request.path is /interOp companies#index is launched, and are
displayed 10 companies with pagination.
When I click for displaying page 2 companies#index is launched but the
path is not /interOp/companies......... but is
/intraOp/companies.........that is because companies#index is first
matched with "intraOp".
Have you some suggestions to solve the problem to having different
layouts based on user?
I prefer to not create two controllers: intraOp and interOp.

Sorry for my ignorance, can you explain better?

I want to display different layouts based on user.
If user is "intraOp" the I want to use layout intraOp, if user is
"interOp" I want to display layout interOp while if controller_devise
I want to display application layout.
I based the user selection on request.path.
If request.path is /intraOp then I select user IntraOp, if /interOp
then select user interOp and so on.
The routes.rb is:

match "intraOp" => "companies#index"
match "interOp" => "companies#index"

The problem is that I use pagination.
When the request.path is /interOp companies#index is launched, and are
displayed 10 companies with pagination.
When I click for displaying page 2 companies#index is launched but the
path is not /interOp/companies......... but is
/intraOp/companies.........that is because companies#index is first
matched with "intraOp".
Have you some suggestions to solve the problem to having different
layouts based on user?
I prefer to not create two controllers: intraOp and interOp.

----
stuff the 'company' into the users session and you can use the session value everywhere, all the time (or not)

Sorry for my ignorance, can you explain better?

I don't know who the user is until it connect to the application.
I use devise.
If the user is signed_in the I want "application" layout and he can
create/modify/destroy.
If the user is not signed in then I must distinguish if to use "intra"
layout or "inter" layout.
To do this I am thinking to set a session variable called, for
example, session[:intra] or session[:inter].
The choice If to use session[:intra][ or session[:inter] is done looking at url.
If localhost/intra then I use "intra" layout and set session[:intra],
if localhost/inter I use "inter" layout and set session[:inter].
What do you think about?

Wouldn't it be simpler to have something like session[:layout] and
only have one place to check? :slight_smile:

(You could set it to "application" at login, as well.)