Reputation: 597
I have an admin namespace and a scaffold of companies placed out of the admin namespace.
I wanted to put the companies into admin namespace
Then I put the companies_controller into admin directory and changed the definition to
class Admin::CompaniesController < Admin::AdminController
and put the companies views into the admin directory in /app/views/
and put the companies_helper into admin directory and now it looks as follows:
module Admin::CompaniesHelper end
The namespace in routes.rb:
namespace :admin do root :to => "companies#index" resources :companies end
When I go to localhost:3000/admin I get this error:
undefined method `company_path' for #:0xb696b408>
Now please tell me how to edit the links to make the links work properly?
Upvotes: 4
Views: 4074
Reputation: 539
Since company is under the namespace admin you have to prefix the path with admin.
Like so:
admin_company_path(@company)
See this Rails guide for more info on Rails routing and namespaces.
Upvotes: 2
Reputation: 835
When you moved the controller in to the admin namespace you changed routes to the links created in the scaffolded templates. For example if your templates use company_path the links would change to admin_company_path.
To view the routes within your application at any given point in time, run "rake routes" from the command line within the root of your rails application. This will show you all the routes within you application
Upvotes: 4
Reputation: 597
I got the kind of ugly solution but it works. I generated a new scaffold but differently:
rails generate scaffold Admin::Companies
instead of
rails generate scaffold Companies
but I still don't understand how the helpers make url for the resources :(
Upvotes: 0