I created a routing test rails3 app with one model 'User':
rails new routing_test_app
rails generate model User name:string
rails generate scaffold_controller admin/user
rake db:migrate
Added to routes.db:
namespace :admin do
resources :users
end
rake routes
admin_users GET /admin/users(.:format) {:action=>"index", :controller=>"admin/users"}
admin_users POST /admin/users(.:format) {:action=>"create", :controller=>"admin/users"}
new_admin_user GET /admin/users/new(.:format) {:action=>"new", :controller=>"admin/users"}
edit_admin_user GET /admin/users/:id/edit(.:format) {:action=>"edit", :controller=>"admin/users"}
admin_user GET /admin/users/:id(.:format) {:action=>"show", :controller=>"admin/users"}
admin_user PUT /admin/users/:id(.:format) {:action=>"update", :controller=>"admin/users"}
admin_user DELETE /admin/users/:id(.:format) {:action=>"destroy", :controller=>"admin/users"}
views/admin/users/_form.html.erb
<%= form_for(@admin_user) do |f| %>
<% if @admin_user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@admin_user.errors.count, "error") %> prohibited this admin_user from being saved:</h2>
<ul>
<% @admin_user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.text_field :name %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
When I go to 'http://localhost:3000/admin/users/new' rails throws an error:
undefined method `users_path' for #<#<Class:0x0000010116ca90>:0x000001011588d8>
Extracted source (around line #1):
1: <%= form_for(@admin_user) do |f| %>
2: <% if @admin_user.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@admin_user.errors.count, "error") %> prohibited this admin_user from being saved:</h2>
In its simplest form, a Namespace Routing Language (NRL) schema consists of a mapping from namespace URIs to schema URIs. An NRL schema is written in XML. DSDL Part 4 (ISO/IEC 19757-4), NVDL is based on NRL.
Routing concerns allow you to declare common routes that can be reused inside other resources and routes.
A namespace is a container for multiple items which includes classes, constants, other modules, and more.
That's because @admin_user
is a User
object, so Rails guesses the URL helper to be users_path
. It's a simple fix. Just replace @admin_user
form_for
param with [:admin, @admin_user]
. You might also want to rename the instance variable @user
for less repitition. Having to use the array is a drawback of using namespaces, so one should always take that into consideration.
The form_for
method will not guess nested routes. Try this:
form_for [:admin, @admin_user] do |f|
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With