简体   繁体   English

Rails:动态生成的路径是在末尾添加句点和id

[英]Rails: dynamically generated path is adding a period and the id at the end

I have the following:我有以下内容:

# /config/routes.rb
resources :employees, :as => :firm_employments, :controller => :firm_employments do
  resource :user_account
end

However, I'm getting the following:但是,我得到以下信息:

@firm_employment = FirmEmployment.find(1)
@user_account = @firm_employment.employee.user_account
firm_employment_user_account_path(@firm_employment, @user_account) # => '/employees/1/user_account.3'

Why is a period and the @user_account id being appended to this path?为什么将句点和@user_account id 附加到此路径? I'm trying to get it to return simply: "/employees/1/user_account"我试图让它简单地返回:“/employees/1/user_account”

Thanks in advance.提前致谢。

If there's only one of a particular resource, then you don't pass in the id, as it's implicit:如果只有一个特定资源,则不要传入 id,因为它是隐式的:

firm_employment_user_account_path(@firm_employment)

What you're doing is supplying @user_account as the :format option, so of course it goes at the end after a period.您正在做的是提供@user_account作为:format选项,所以它当然会在一段时间后结束。

If you have more than one, you need to define the route differently:如果您有多个,则需要以不同的方式定义路由:

resources :user_accounts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM