martins
martins

Reputation: 10009

form_for creates the wrong url

I'm creating a form that should post to /users/:user_id/user_languages The form view looks like this: form_for user_user_languages_url(@user) do |f|

But when I render the page and inspect the form, the URL it uses is like this. How can that be? :-(

rake routes

     user_user_languages GET    /users/:user_id/user_languages(.:format)                       user_languages#index
                         POST   /users/:user_id/user_languages(.:format)                       user_languages#create

Upvotes: 0

Views: 77

Answers (1)

EugZol
EugZol

Reputation: 6545

It seems that you need to provide user_id to your helper:

form_for user_user_languages_url(user_id: @user.id)

By default, URL helper will set id parameter from the provided object. But you need user_id instead.

Upvotes: 1

Related Questions