0

Company belongs_to Users and a Company has_many Quotes. If a User is logged_in, and has a company created in the db, I would like to root to Quotes#new, which requires the company_id to be passed in. I can't seem to pass an argument into the root call, could you advise how I could achieve, a) a conditional root based upon logged in status and b) routing to a nested controller that requires parent id to be passed.

both:

root 'quotes#new', company_id: company.id

and:

root 'quotes#new', current_user

result in Couldn't find Company with 'id'=

Thanks.

Info I'm finding to help me with this:

http://minhajuddin.com/2011/10/24/how-to-change-the-rails-root-url-based-on-the-user-or-role/

Rails Routes based on condition

http://bjedrocha.com/rails/2015/03/18/role-based-routing-in-rails/

https://robots.thoughtbot.com/constrain-yourself

jbk
  • 1,911
  • 19
  • 36
  • 1
    Any particular reason why this should be done in routes? Why not in a controller and redirect from there? – Gerry Jul 05 '17 at 20:49
  • Are you using Devise? – Pavan Jul 06 '17 at 05:15
  • No reason why it can't be done in a controller. I am using Devise. – jbk Jul 06 '17 at 11:46
  • You can't use `root` like that, by definition there are no parameters in the path. If a company has many quotes then it's usually a nested `resources` structure you define in your routes. – tadman Jul 06 '17 at 21:03
  • Getting a better grip on what i need to do now i think guys, root to a custom controller, perhaps Homepage, which runs a method to determine whether there's a devise logged in user, if true go here, if false go there. Slowly piecing together how to write it. – jbk Jul 06 '17 at 21:12

0 Answers0