Rails 5 link_to中的URL不正确

时间:2017-11-14 17:04:40

标签: ruby-on-rails

在我的OrganizationsController中有这个:

class OrganizationsController < ApplicationController
before_action :require_login

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

end

并在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>

路线:

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

Link_to生成此网址:

/organizations/126/repositories/3

而organization_id为3且repository_id为126,因此URL应该是:

/organizations/3/repositories/126

如何生成正确的网址?

/organizations/3/repositories/126

0 个答案:

没有答案