Note that there are some explanatory texts on larger screens.

plurals
  1. POIncorrect Nested Module Routes
    text
    copied!<p>I'll preface this with the fact that I'm new to RoR. I have a class that resides in a nested module, <code>::Physical::Users::User</code>. The code is organized into paths such as app\controllers\physical\users. </p> <p>My problem comes when I try to use <code>form_for</code> like this:</p> <pre><code>&lt;% form_for @user do |f| %&gt; ... &lt;% end %&gt; </code></pre> <p>I get the error <code>ActionView::TemplateError undefined method 'physical_users_users_path'</code></p> <p>I understand that this has to do with rails expecting routes that don't match mine. In order to make my app work so that the resource :users goes directly to the correct directory (so that I don't have to use http:\myurl.com\physical\users\users\1', I put the following in my routes.rb file:</p> <pre><code>map.resources :users, :controller =&gt; 'physical/users/users' </code></pre> <p>When I run ">rake routes" I get the following:</p> <pre><code> users GET /users(.:format) {:controller=&gt;"physical/users/users", :action=&gt;"index"} POST /users(.:format) {:controller=&gt;"physical/users/users", :action=&gt;"create"} new_user GET /users/new(.:format) {:controller=&gt;"physical/users/users", :action=&gt;"new"} edit_user GET /users/:id/edit(.:format) {:controller=&gt;"physical/users/users", :action=&gt;"edit"} user GET /users/:id(.:format) {:controller=&gt;"physical/users/users", :action=&gt;"show"} PUT /users/:id(.:format) {:controller=&gt;"physical/users/users", :action=&gt;"update"} DELETE /users/:id(.:format) {:controller=&gt;"physical/users/users", :action=&gt;"destroy"} /:controller/:action/:id /:controller/:action/:id(.:format) </code></pre> <p>Is there a way to maintain the shorter url to my user resource and get <code>form_for</code> to look for the correct route?</p> <p>Again, I'm new, so if there's anything I'm missing in this explanation, let me know!</p> <p>--</p> <p>In response to replies below, the controller resides at app/controllers/physical/users/users_controller.rb.</p> <p>Changing the routing to use namespaces like:</p> <pre><code>map.namespace :physical do |physical| physical.namespace :users do |users| users.resources :users end end </code></pre> <p>generates routes that are consistent with what <code>form_for</code> is looking for, but then I lose the ability to use the URL http:\mysite.com\users\1.</p> <p>Thanks for the help so far!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload