1

I've created a new page and for some reason i cannot find it.

I've used rails generate controller dashboard index Which worked fine. I then went into the routes file and added this

namespace :dashboard do
  get 'dashboard' => 'dashboard#index'
end

My file tree is like this views --> dashboard --> index.html.erb

My helper is just this

module DashboardHelper
end

my controller has just got the def index end inside

Any ideas what im doing wrong?

if i go to /dashboard i get this error No route matches [GET] "/dashboard"

Cheers

5
  • What does the error say? Commented Aug 21, 2015 at 15:18
  • Sorry i'll add that in now Commented Aug 21, 2015 at 15:19
  • try /dashboard/dashboard Commented Aug 21, 2015 at 15:23
  • uninitialized constant Dashboard::DashboardController Commented Aug 21, 2015 at 15:25
  • if get 'dashboard' => 'dashboard#index' outside namespace in your routes it will work, else your controller should have Dashboard::DashboardController < ApplicationController and views folder structure should be /dashboard/dashboard/index.html.erb Commented Aug 21, 2015 at 15:27

2 Answers 2

3

If you are use a namespace option in routes.rb, you should wrap your controller class in namespace also you should put it in own folders.

To make it faster delete your current controller:

rails destroy controller dashboard

And generate new:

rails generate controller dashboard/dashboard index

Rails generate for you controller, inserts the right routes and add views.

$> rails generate controller dashboard/dashboard index
#> create  app/controllers/dashboard/dashboard_controller.rb
#>  route  namespace :dashboard do
#>    get 'dashboard/index'
#>  end
#> invoke  erb
#> create    app/views/dashboard/dashboard
#> create    app/views/dashboard/dashboard/index.html.erb
Sign up to request clarification or add additional context in comments.

2 Comments

So i followed this, Then went to dashboard/dashboard and nothing worked got this error ActionController::RoutingError at /dashboard/dashboard uninitialized constant Dashboard::Controller
do you restart the server? and actual route url dashboard/dashboard/index according routes.rb
0

Your dashboard controller should be

class Dashboard::DashboardController < ApplicationController
   def index
   end
end

Your view folder structure should be

views -> dashboard -> dashboard -> index.html.erb

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.