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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 30, 2011, at 3:31 PM, Mauro wrote:> 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) Craig -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 December 2011 00:54, Craig White <craig.white-wmL3h9Ogt9DQT0dZR+AlfA@public.gmane.org> wrote:> > On Nov 30, 2011, at 3:31 PM, Mauro wrote: > >> 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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 1, 2011, at 8:28 AM, Mauro wrote:> On 1 December 2011 00:54, Craig White <craig.white-wmL3h9Ogt9DQT0dZR+AlfA@public.gmane.org> wrote: >> >> On Nov 30, 2011, at 3:31 PM, Mauro wrote: >> >>> 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?---- 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 December 2011 17:13, Craig White <craig.white-wmL3h9Ogt9DQT0dZR+AlfA@public.gmane.org> wrote:> > On Dec 1, 2011, at 8:28 AM, Mauro wrote: > >> On 1 December 2011 00:54, Craig White <craig.white-wmL3h9Ogt9DQT0dZR+AlfA@public.gmane.org> wrote: >>> >>> On Nov 30, 2011, at 3:31 PM, Mauro wrote: >>> >>>> 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? > ---- > 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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2011-Dec-05 15:32 UTC
Re: routes matching different path for different users.
On Mon, Dec 5, 2011 at 3:13 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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? :-) (You could set it to "application" at login, as well.) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.