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.

On Nov 30, 2011, at 3:31 PM, Mauro wrote:

match “interOp” => “companies#index”
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)

Craig

On 1 December 2011 00:54, Craig W. [email protected] wrote:

The routes.rb is:
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?

On Dec 1, 2011, at 8:28 AM, Mauro wrote:

then select user interOp and so on.
/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?


when the user logs in, set a session variable…
session[:company] = @user.company
and whenever you need to build a url with the company, include the
session[:company] in the url or if universal, you can probably add it to
your routes.

Craig

On 1 December 2011 17:13, Craig W. [email protected] wrote:

I want to display application layout.
displayed 10 companies with pagination.
Sorry for my ignorance, can you explain better?


when the user logs in, set a session variable…
session[:company] = @user.company
and whenever you need to build a url with the company, include the
session[:company] in the url or if universal, you can probably add it to your
routes.

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?

On Mon, Dec 5, 2011 at 3:13 AM, Mauro [email protected] wrote:

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.)


Hassan S. ------------------------ [email protected]

twitter: @hassan