Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4616

form_with is trying to generate the action with the wrong path

$
0
0

I'm experimenting with routing and namespaces.

When implementing a form with <%= form_with model: [@user, @address] do |form| %>i receive this error undefined method 'customer_user_customer_addresses_path'

This is the routing schema

  namespace :customer do    resources :users do      resource :contact      resources :addresses    end  end  resolve('Customer::Contact') {    [:customer, :user, :contact]  }

All routes printed by rails routes command are as expected.

                 customer_user_addresses GET    /customer/users/:user_id/addresses(.:format)                                                      customer/addresses#index                                         POST   /customer/users/:user_id/addresses(.:format)                                                      customer/addresses#create               new_customer_user_address GET    /customer/users/:user_id/addresses/new(.:format)                                                  customer/addresses#new              edit_customer_user_address GET    /customer/users/:user_id/addresses/:id/edit(.:format)                                             customer/addresses#edit                   customer_user_address GET    /customer/users/:user_id/addresses/:id(.:format)                                                  customer/addresses#show                                         PATCH  /customer/users/:user_id/addresses/:id(.:format)                                                  customer/addresses#update                                         PUT    /customer/users/:user_id/addresses/:id(.:format)                                                  customer/addresses#update                                         DELETE /customer/users/:user_id/addresses/:id(.:format)                                                  customer/addresses#destroy

This is what i was able to do

  • by creating the Customer::UsersController i was able to access all crud operations for the users resources
  • by creating the Customer::ContactsController i was able to access all crud operations but i had to add the resolve directive in order to make the routes generated correctly
  resolve('Customer::Contact') {    [:customer, :user, :contact]  }

This is where i'm in trouble

When implementing the Customer::AddressesController i can't figure out a way to make form_with requesting the correct path.

This is the controller action

  def new    @breadcrumbs = []    @user = Customer::User.find(params[:user_id])    @address = @user.addresses.build  end

This is the new template

<%= form_with model: [@user, @address] do |form| %>

When i navigate to the new action i get this error undefined method 'customer_user_customer_addresses_path'

In order to make it working i had to pass an url parameter with the correct path: <%= form_with model: [@user, @address], url: customer_user_addresses_path(@user) do |form| %>.

What convention am i missing? is there any way to omit the url parameter?


Viewing all articles
Browse latest Browse all 4616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>