Search code examples
ruby-on-rails-3routescustom-routesnested-routes

How can I route a nested resource to an alias?


I know it's not advised to go more then 1 level deep in nested routes but here's what I have:

  resources :partners do
    resources :recommend_partners do
      resources :rec_partner_comments
    end
  end

Is there a way that I can call an alias to use the name_route

So instead of using

new_partner_recommend_partner_rec_partner_comments

I'll use something like

new_comment_on_pr

Just a thought...


Solution

  • You can always create a helper function

    def new_comment_on_pr(*args)
      new_partner_recommend_partner_rec_partner_comments(*args)
    end
    

    Also do you know of a more clear route path syntax in Rails? Instead of

    partner_recommend_partner_rec_partner_comments(partner, recommend_partner)
    

    you can write

    [partner, recomment_partner, :comments]