Rails routing error after scaffolding? - ruby

So I'm receiving a routing error No route matches [GET] "/"
my routes.rb:
Webapp::Application.routes.draw do
resources :ideas
end
I scaffolded this ideas controller together by running this in my projects folder:
$ rails generate scaffold idea name:string description:text picture:string
$ rake db:migrate
$ rails s
& thats when I received the routing error.

What do you have for root :to => in routes.rb?
This determines [GET] "/"

Related

No route matches [GET] "/" when trying to add the gem devise

The error comes with
Please add some routes in config/routes.rb.
routes.rb already has
devise_for :users
I am not sure how to fix this error. I have tried rake routes in the GIT terminal with the result:
rake aborted!
Don't know how to build task 'routes' (See the list of available tasks with `rake --tasks`)
Running in development mode on local server.
So few things:
Firstly, rake routes has been removed - I have no idea why tbh, but it is rails routes now instead.
Secondly, devise is adding its routes, but you still need to have some ohter content that devise is to guard access to. You can create a simple HomeController:
class HomeController < ApplicationController
def show
render html: "home"
end
end
and use this as your root route:
# routes.rb
devise_for ...
root to: "home#show"

Routes not matching in Rspec tests

I can't seem to get a matching route in my rspec tests and I am not quite sure why.
routes.rb
resources :admins, only: [:index] do
get 'configs', on: :collection, to: 'admins#configs'
end
Rspec response
Failure/Error: get '/admins/config'
ActionController::RoutingError:
No route matches [GET] "/admins/config"
I run rails routes | grep config and this is the response so I think I am using the correct route
configs_admins GET /admins/configs(.:format) admins#configs
You defined '/admins/configs' (plural) but you're trying to access '/admins/config' (singular).

Rails 4: Own engine "No route matches"

I write..
rails new testapp
cd testapp/
rails plugin new blog --mountable
cd blog/
rails g scaffold post name description:text
rake db:migrate
cd ../
rails s
Go to localhost:3000/blog/posts/index and i get error "No route matches [GET] "/blog/posts/index""
What i'm doing wrong?
Putting the engine at some random directory inside your application won't make it magically work. I don't know where you learned this technique from, but it is wrong.
You should put the engine outside your application and require it into your application's Gemfile, like this:
gem 'blog', :path => '../blog'
Then the engine will be automatically loaded by Rails.
The Engines Guide goes into more detail. I highly recommend reading that.

Active Admin uninitialized constant Admin::DashboardController

I just migrated a Rails app to 3.1. Active Admin is now 0.6.0. That's my routes.rb
AppName::Application.routes.draw do
root :to => "homepage#index"
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
So root is declared before ActiveAdmin routes. We I start the server in development and I reload the browser I get the ActiveAdmin interface here:
http://localhost:3000/admin
When I reload that URL I get:
uninitialized constant Admin::DashboardController
I found several issues:
assets generator must best execute after an update;
controllers/admin clashes with ActiveAdmin route;
root directive should be define before ActiveAdmin route.
To fix number one:
$> rails generate active_admin:assets
To fix number two:
config.default_namespace = :your_desired_namespace
To fix number three just move root up (in config/routes.rb)

Rails3 Routing error. No route matches {:action=>"destroy"

I'm following the guide at, http://guides.rubyonrails.org/getting_started.html
Ruby 1.9.2p0
Rails 3.0.0
But I'm locked at 6.2/6.3, when I try to add the;
I get the error (I switched the Post example to Specie);
ActionController::RoutingError in Home#index
No route matches {:action=>"destroy", :controller=>"species"}
Terminal history:
bundle install
rake db:create
rails generate controller home index
rm public/index.html
rails generate scaffold Specie name:string latin:string
rake db:migrate
The path localhost:3000/species/ works but not localhost:3000/species/new
Rake routes:
species_index GET /species(.:format) {:action=>"index", :controller=>"species"}
species_index POST /species(.:format) {:action=>"create", :controller=>"species"}
new_species GET /species/new(.:format) {:action=>"new", :controller=>"species"}
edit_species GET /species/:id/edit(.:format) {:action=>"edit", :controller=>"species"}
species GET /species/:id(.:format) {:action=>"show", :controller=>"species"}
species PUT /species/:id(.:format) {:action=>"update", :controller=>"species"}
species DELETE /species/:id(.:format) {:action=>"destroy", :controller=>"species"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root /(.:format) {:controller=>"home", :action=>"index"}
routes.rb
resources :species
get "home/index"
root :to => "home#index"
Your problem is that the plural of species is species (they are the same).
The answer is in your rake routes. Note you'll want to use:
<%= link_to "All Species", species_index_path %>
See Section 4.8 - Overriding The Singular Form in the Routing guide for more info.

Resources