Rails 3 namespace routing
class Admin::CompaniesController < Admin::AdminController
and put the companies views into the admin directory in /a开发者_如何转开发pp/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?
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
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.
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 :(
精彩评论