Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 544
robertwbradford Avatar asked May 02 '11 15:05

robertwbradford


1 Answers

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
like image 98
tadman Avatar answered Nov 15 '22 20:11

tadman