Ruby on rails RubyonRails:';显示';结算途径

Ruby on rails RubyonRails:';显示';结算途径,ruby-on-rails,controller,routes,Ruby On Rails,Controller,Routes,目前我有两种型号,Account和User。帐户有多个用户,用户属于帐户。我想显示帐户页面,但一直没有得到任何路由匹配{:action=>“show”,:controller=>“accounts”},缺少必需的键:[:id]错误 账户控制器 def show @account = Account.find_by(params[:id]) end 帐户页面的链接 <%= link_to "Account Settings", account_path %> 这里的问题是:

目前我有两种型号,
Account
User
。帐户有多个用户,用户属于帐户。我想显示帐户页面,但一直没有得到任何路由匹配{:action=>“show”,:controller=>“accounts”},缺少必需的键:[:id]错误

账户
控制器

def show
   @account = Account.find_by(params[:id])
end
帐户页面的链接

<%= link_to "Account Settings", account_path %>
这里的问题是:

<%= link_to "Account Settings", account_path %>
将在数据库中找到您的记录,并将您重定向到:show page


<%= link_to "Account Settings", account_path(@current_user.account_id) %>

我将链接修改为
,它可以正常工作!虽然此代码可能会回答该问题,但提供有关此代码为什么和/或如何回答该问题的附加上下文可提高其长期价值。
<%= link_to "Account Settings", account_path(123) %>
@account = Account.find_by(params[:id])
<%= link_to "Account Settings", account_path(@current_user.account_id) %>