This project is archived and is in readonly mode.
[PATCH]Rails 3 : Namespace problem in Scaffold
Reported by siddick | June 4th, 2010 @ 07:02 AM | in 3.0.2
I used the following command to generate the scaffold.
rails g scaffold admin/role name:string description:string
frozen_role:boolean
I run the application it produce the routing Error( No route
matches "/admin/roles" ) for the following url.
http://localhost:3000/admin/roles
Then i changed the url( http://localhost:3000/roles ), it
produce the Routing Error( uninitialized constant RolesController
).
Actual configuration in the routes.rb is
routes :roles But the expected is
namespace :admin do
resources :roles
end
So, I modified the routes.rb manually and check it, then also i
face the problem.
I did many modification in controller and erb fils to make it
work.
The problem because of using "roles" instead of
"admin_roles"
-- ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]
Rails 3.0.0.beta3
Comments and changes to this ticket
-
siddick June 4th, 2010 @ 07:05 AM
Actual configuration in the routes.rb is
resources :rolesBut the expected is
namespace :admin doresources :roles
end
-
siddick June 4th, 2010 @ 01:04 PM
- Title changed from Generate Scaffold problem to Rails 3 : Namespace problem in Scaffold
-
siddick June 10th, 2010 @ 11:13 AM
- Tag changed from 3.0.0.beta3 to 3.0.0.beta3, patch
- Title changed from Rails 3 : Namespace problem in Scaffold to [PATCH]Rails 3 : Namespace problem in Scaffold
I created PATCH, which will solve the namespace problem in scaffold.
Steps to reproduce the BUG( Rails 3.0.0.beta4, ruby 1.8.7 ) :-
siddick@Aristo32:~$ rails new rt siddick@Aristo32:~$ cd rt siddick@Aristo32:~/rt$ rails g scaffold admin/role name:string description:string invoke active_record create db/migrate/20100609114623_create_admin_roles.rb create app/models/admin/role.rb create app/models/admin.rb invoke test_unit create test/unit/admin/role_test.rb [BUG] create test/fixtures/admin_roles.yml [BUG] route resources :roles invoke scaffold_controller create app/controllers/admin/roles_controller.rb invoke erb create app/views/admin/roles create app/views/admin/roles/index.html.erb create app/views/admin/roles/edit.html.erb create app/views/admin/roles/show.html.erb create app/views/admin/roles/new.html.erb create app/views/admin/roles/_form.html.erb invoke test_unit create test/functional/admin/roles_controller_test.rb invoke helper create app/helpers/admin/roles_helper.rb invoke test_unit create test/unit/helpers/admin/roles_helper_test.rb invoke stylesheets create public/stylesheets/scaffold.css siddick@Aristo32:~/rt$ rake routes GET /roles(.:format) {:controller=>"roles", :action=>"index"} roles POST /roles(.:format) {:controller=>"roles", :action=>"create"} new_role GET /roles/new(.:format) {:controller=>"roles", :action=>"new"} GET /roles/:id(.:format) {:controller=>"roles", :action=>"show"} PUT /roles/:id(.:format) {:controller=>"roles", :action=>"update"} role DELETE /roles/:id(.:format) {:controller=>"roles", :action=>"destroy"} edit_role GET /roles/:id/edit(.:format) {:controller=>"roles", :action=>"edit"} siddick@Aristo32:~/rt$ rake db:migrate siddick@Aristo32:~/rt$ rake test Loaded suite /home/siddick/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader Started . Finished in 0.119779 seconds. 1 tests, 1 assertions, 0 failures, 0 errors Loaded suite /home/siddick/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader Started EEEEEEE Finished in 0.120718 seconds. 1) Error: test_should_create_role(Admin::RolesControllerTest): FixtureClassNotFound: No class attached to find. /test/functional/admin/roles_controller_test.rb:5:in `_callback_before_33' 2) Error: test_should_destroy_role(Admin::RolesControllerTest): FixtureClassNotFound: No class attached to find. /test/functional/admin/roles_controller_test.rb:5:in `_callback_before_33' 3) Error: test_should_get_edit(Admin::RolesControllerTest): FixtureClassNotFound: No class attached to find. /test/functional/admin/roles_controller_test.rb:5:in `_callback_before_33' 4) Error: test_should_get_index(Admin::RolesControllerTest): FixtureClassNotFound: No class attached to find. /test/functional/admin/roles_controller_test.rb:5:in `_callback_before_33' 5) Error: test_should_get_new(Admin::RolesControllerTest): FixtureClassNotFound: No class attached to find. /test/functional/admin/roles_controller_test.rb:5:in `_callback_before_33' 6) Error: test_should_show_role(Admin::RolesControllerTest): FixtureClassNotFound: No class attached to find. /test/functional/admin/roles_controller_test.rb:5:in `_callback_before_33' 7) Error: test_should_update_role(Admin::RolesControllerTest): FixtureClassNotFound: No class attached to find. /test/functional/admin/roles_controller_test.rb:5:in `_callback_before_33' 7 tests, 0 assertions, 0 failures, 7 errors
After applying the PATCH :-
siddick@Aristo32:~/rt$ siddick@Aristo32:~$ rails new rt siddick@Aristo32:~$ cd rt siddick@Aristo32:~/rt$ rails g scaffold admin/role name:string description:string invoke active_record create db/migrate/20100609123955_create_admin_roles.rb create app/models/admin/role.rb create app/models/admin.rb invoke test_unit create test/unit/admin/role_test.rb create test/fixtures/admin/roles.yml route namespace :admin do resources :roles end invoke scaffold_controller create app/controllers/admin/roles_controller.rb invoke erb create app/views/admin/roles create app/views/admin/roles/index.html.erb create app/views/admin/roles/edit.html.erb create app/views/admin/roles/show.html.erb create app/views/admin/roles/new.html.erb create app/views/admin/roles/_form.html.erb invoke test_unit create test/functional/admin/roles_controller_test.rb invoke helper create app/helpers/admin/roles_helper.rb invoke test_unit create test/unit/helpers/admin/roles_helper_test.rb invoke stylesheets create public/stylesheets/scaffold.css siddick@Aristo32:~/rt$ rake routes GET /admin/roles(.:format) {:controller=>"admin/roles", :action=>"index"} admin_roles POST /admin/roles(.:format) {:controller=>"admin/roles", :action=>"create"} new_admin_role GET /admin/roles/new(.:format) {:controller=>"admin/roles", :action=>"new"} GET /admin/roles/:id(.:format) {:controller=>"admin/roles", :action=>"show"} PUT /admin/roles/:id(.:format) {:controller=>"admin/roles", :action=>"update"} admin_role DELETE /admin/roles/:id(.:format) {:controller=>"admin/roles", :action=>"destroy"} edit_admin_role GET /admin/roles/:id/edit(.:format) {:controller=>"admin/roles", :action=>"edit"} siddick@Aristo32:~/rt$ rake db:migrate siddick@Aristo32:~/rt$ rake test Loaded suite /home/siddick/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader Started . Finished in 0.180626 seconds. 1 tests, 1 assertions, 0 failures, 0 errors Loaded suite /home/siddick/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake/rake_test_loader Started ....... Finished in 0.301821 seconds. 7 tests, 10 assertions, 0 failures, 0 errors
Testing :-
I added testcase to test the namespace problem in scaffold.
rake test:regular TEST=test/generators/scaffold_generator_test.rb
-
siddick June 18th, 2010 @ 12:25 PM
- Tag changed from 3.0.0.beta3, patch to rails 3.0.0.beta4, patch, scaffold
Any Updates on this bug..
-
José Valim June 21st, 2010 @ 10:36 AM
- Milestone cleared.
- State changed from new to open
- Assigned user set to José Valim
Hey mate, thanks for the awesome patch with tests! However, it needs to be rebased, could you do it? (Sorry for not being able to see it earlier)
Also, I have one suggestion. I noticed you changed all orm_instance calls to orm_instance(singular_table_name). Wouldn't it be better if you simply change the default value given to orm_instance instead:
http://github.com/rails/rails/blob/master/railties/lib/rails/genera...
It could use singular_table_name instead of file_name.
-
José Valim June 21st, 2010 @ 10:44 AM
- Milestone cleared.
-
siddick June 23rd, 2010 @ 08:22 AM
I attached the New Patch, with the changes that you have suggested.
-
Repository June 23rd, 2010 @ 08:32 AM
- State changed from open to resolved
(from [7008911222826eef07a338bf4cab27b83fe90ce1]) Patch for Namespace problem in Scaffold. [#4763 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/7008911222826eef07a338bf4cab27... -
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to Low
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 4763 [PATCH]Rails 3 : Namespace problem in Scaffold (from [7008911222826eef07a338bf4cab27b83fe90ce1]) Patch f...