Ruby on rails 没有路由匹配{:action=>;show";,:controller=>;profiles";,:user\u id=>;nil},缺少必需的键:[:user\u id]

Ruby on rails 没有路由匹配{:action=>;show";,:controller=>;profiles";,:user\u id=>;nil},缺少必需的键:[:user\u id],ruby-on-rails,Ruby On Rails,我的视图不知何故没有获得控制器的show操作,并且不知何故返回user_id nil。基本上我有一个UsersController和一个ProfilesController,我在Users中显示,用名字和姓氏索引所有用户 <% @users.each do |user| %> <table style="width:50%"> <tr> <th><%= link_to 'Show user profile', user_profile

我的视图不知何故没有获得控制器的show操作,并且不知何故返回user_id nil。基本上我有一个UsersController和一个ProfilesController,我在Users中显示,用名字和姓氏索引所有用户

<% @users.each do |user| %>
<table style="width:50%">
<tr>
    <th><%= link_to 'Show user profile', user_profile_path(@profile) %> <%= user.first_name%>   <%= user.last_name%></th>

</tr>
</table>

<% end %>
我还试着做了以下实验:

<%= link_to 'Show user profile', user_profile_path(@user) %>
<%= link_to 'Show user profile', user_profile_path(@user.profile) %>
<%= link_to 'Show user profile', user_profile_path(@user,@profile) %>
<%= link_to 'Show user profile', user_profile_path(@user,profile) %>


。。。但都不管用。谢谢大家!

您需要在链接中传递
用户id
,请改用此链接

<%= link_to 'Show user profile', user_profile_path(user, @profile) %> 

因为它是嵌套路由,所以需要传递两个对象/ID


希望有帮助

请显示您的
config/routes.rb
文件
Request

Parameters:

None
<%= link_to 'Show user profile', user_profile_path(@user) %>
<%= link_to 'Show user profile', user_profile_path(@user.profile) %>
<%= link_to 'Show user profile', user_profile_path(@user,@profile) %>
<%= link_to 'Show user profile', user_profile_path(@user,profile) %>
<%= link_to 'Show user profile', user_profile_path(user, @profile) %>