gotqn
gotqn

Reputation: 43666

path helper for form_for tag with url options generates wrong url

I am using form_for helper with url option like this:

<%= form_for  @security_user, url: security_users_manage_securities_path(@security_user),
              html: { class: 'default', method: :put, id: 'security-default-form' } do |f| %>

but the

security_users_manage_securities_path(@security_user)

returns me the following string:

/security_users_manage_securities.105

when I need the following one:

/security_users_manage_securities/105

Has anyone un idea why the id of the @security_user parameter is concatenated with '.' instead '/'?

Upvotes: 0

Views: 367

Answers (2)

uma
uma

Reputation: 2962

I have faced this problem already.

It may be possible, you have define your route for 'security_users_manage_security' with collection like

collection do 
  post :security_users_manage_securities
end
or 
post :security_users_manage_securities, :on => collection

if you hit rake routes | grep security_users_manage_securities command on terminal, then you will find route for security_users_manage_securities something like this

controller_name/method_name(.:format)    controller_name#method_name

there is no option to pass any argument in url.

If you have to make url with parameter then define url with member.

If you have to pass parameter in this condition also, then you define your url some like

security_users_manage_securities_path(:user_id => @security_user)

now url will be generated something like controller_name/method_name?user_id = XXX

Upvotes: 0

sampi
sampi

Reputation: 585

Try to use this helper in singular mode, e.g.

security_users_manage_security_path(@security_user)

This should generate

/security_users_manage_securities/105

Plural is used when you want to get url to list and then you shouldn't pass any params:

security_users_manage_securities_path

returns:

/security_users_manage_securities

Upvotes: 1

Related Questions