0

In my OrganizationsController in have this:

class OrganizationsController < ApplicationController
before_action :require_login

  def show
    @organization = current_user.organizations.find(params[:id])
  end

end

And in show.html.erb

<% @organization.repositories.each do |repository| %>
  <%= link_to repository.name, organization_repository_path(repository) %>
<% end %>

Params:

Parameters <ActionController::Parameters {"controller"=>"organizations", "action"=>"show", "id"=>"3"} permitted: false>

routes:

URI pattern:
organization_repository GET /organizations/:organization_id/repositories/:id(.:format)

Link_to generates this URL:

/organizations/126/repositories/3

Whereas the organization_id is 3 and repository_id is 126 so the URL should rather be:

/organizations/3/repositories/126

How to generate proper URL?

/organizations/3/repositories/126
jedi
  • 2,003
  • 5
  • 28
  • 66
  • 1
    This might help you: https://stackoverflow.com/questions/25269232/how-do-you-pass-multiple-arguments-to-nested-route-paths-in-rails – Felipe Freitag Vargas Nov 14 '17 at 17:11
  • You are absolutely brilliant! I've been fighting with this the WHOLE DAY! Thank you so much:) – jedi Nov 14 '17 at 17:18
  • Possible duplicate of [How do you pass multiple arguments to nested route paths in Rails?](https://stackoverflow.com/questions/25269232/how-do-you-pass-multiple-arguments-to-nested-route-paths-in-rails) – SRack Nov 14 '17 at 17:20

0 Answers0