简体   繁体   中英

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? I'm trying to get it to return simply: "/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:

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.

If you have more than one, you need to define the route differently:

resources :user_accounts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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