Reputation: 8172
I have two controllers dashboard
and posts
. Im trying to put the post's :new, :create, :destroy, :edit, :update
actions within dashboard
url like this dashboard/posts/new
. But the im talking to the new
action in the posts
controller. Not in the dash
controller. Here's my routes.rb
file :
resources :posts, :except => [:new, :create, :destroy, :edit, :update]
get 'dashboard', to: 'dash#show'
namespace :dashboard do
resources :posts, :only => [:new, :create, :destroy, :edit, :update]
end
get 'dashboard/posts', to: 'dash#posts'
The two controllers in question are : dash
and posts
Now when I try to visit http://localhost:3000/dashboard/posts/new
it says :
ActionController::RoutingError at /dashboard/posts/new
uninitialized constant Dashboard
How to fix this?
Upvotes: 1
Views: 1017
Reputation: 53048
Assuming that you have two controllers DashController
and PostsController
.
And you want to access few of the posts routes within the scope of namespace
then you can define the routes as below:
resources :posts, :only => [:index, :show]
get 'dashboard', to: 'dash#show'
scope :dashboard do
resources :posts, controller: :posts ,:only => [:new, :create, :destroy, :edit, :update]
end
get 'dashboard/posts', to: 'dash#posts'
Upvotes: 1
Reputation: 95
The constant "Dashboard" can't be found. I think the problem is that you sometimes use dash
and sometimes use dashboard
.
Upvotes: 0