I am trying to setup role based routing in my application. Something similar to the following: map.root :controller => (authorize_admin? ? ''prospects'' : ''welcome'') I am getting an error that authorize_admin? is not defined. It is defined under lib directory and I can successfully call it from other places in the application. How do you set up conditional root routes for an application? Thanks. Bharat -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Wed, Apr 1, 2009 at 1:24 PM, Bharat Ruparel <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I am trying to setup role based routing in my application. Something > similar to the following: > > map.root :controller => (authorize_admin? ? ''prospects'' : ''welcome'') > > I am getting an error that authorize_admin? is not defined.Require the file from your lib dir, something like: require "#{ RAILS_ROOT }/lib/foo.rb"> It is > defined under lib directory and I can successfully call it from other > places in the application. How do you set up conditional root routes > for an application?-- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you for your response Greg. I found that I was making my code
progressively worse by trying to do the conditional routing in routes.rb
file. Instead, I decided to do it the old-fashioned way as shown below:
<div id="main-navigation">
<% if authorize_admin? %>
<%= navigation [:prospects,{:admin => {:controller =>
''admin'', :action => ''index''}}] %>
<% else %>
<%= navigation [{:welcome => root_path}] %>
<% end %>
<div class="clear"></div>
</div>
This is a snippet of code from my application.html.erb file. I will
most likely refactor it later to create the navigation array in the
application_helper.rb once things settle down.
By the way, I tried what you suggest above. I required the file as you
had outlined and then included it since it is a module but that resulted
in a chain of errors since it requires a slew of other things to be
loaded as well.
Regards,
Bharat
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---