ActionController::RoutingError No route matches [GET] "/stories" - ruby-on-rails

OS: openSUSE 11.4
Rails 3.2.0
I just created a very simple application "koko". Here are the order of commands I ran
rails new koko
rails generate model Story name:string description:string
rake db:migrate
rails generate controller Stories index
All above commands executed successfully.
I then ran =>rails server to start the server.
localhost:3000/ works fine.
When i try to do
localhost:3000/stores I get the following error: (the browser displayes the first line about No route matches)
Started GET "/stories" for 127.0.0.1 at Sat Aug 04 12:52:02 -0400 2012
ActionController::RoutingError (No route matches [GET] "/stories"):
actionpack (3.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.0) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.0) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.0) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.0) lib/rails/engine.rb:479:in `call'
railties (3.2.0) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.0) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.4.1) lib/rack/handler/webrick.rb:13:in `run'
rack (1.4.1) lib/rack/server.rb:265:in `start'
railties (3.2.0) lib/rails/commands/server.rb:70:in `start'
railties (3.2.0) lib/rails/commands.rb:55
railties (3.2.0) lib/rails/commands.rb:50:in `tap'
railties (3.2.0) lib/rails/commands.rb:50
script/rails:6:in `require'
script/rails:6
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.2.0/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.9ms)

Your issue is that you are trying to use a RESTful interface to a non-RESTful resource. You made a model, and you made a controller with an index action, (/controller_name/action).
If you are happy with using /stories/index, then we're done! If you prefer the more traditional RESTful interface /stories, then I would suggest using:
rails generate resource ModelName fields:types.
This will create a Model and a Controller, and should work restfully out of the box. This will set up the route that was mentioned in the comments.
Hope this helps!

You might simply have some naming problems. Generally, when creating a controller it should be
rails g controller stories index
or
rails g controller Story index
Then change your automatically-generated route to
match "/stories" => "stories#index", :as => "stories"

Related

Ruby on Rails devise issues

I have been trying to figure this out for way too long and i am hoping for some help here. I am new to Ruby and downloaded devise gem but when i try to run the sign up page it is giving me this error in my terminal:
Started GET "/users/sign_up" for 127.0.0.1 at 2013-09-11 17:52:28 -0700
ActionController::RoutingError (No route matches [GET] "/users/sign_up"):
actionpack (3.2.12) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.12) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.12) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.12) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.12) lib/rails/engine.rb:479:in `call'
railties (3.2.12) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.12) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Rendered /usr/local/rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/actionpack-3.2.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (3.0ms)
I imagine this means i do not have a route for the sign up page. How do i set that up. I have looked online and tried almost everything and nothing seems to work.
I would first make sure Devise is set up properly, per the instructions here... https://github.com/plataformatec/devise
Specifically (after getting the Devise gem)...
rails generate devise:install
followed by...
rails generate devise MODEL
Where MODEL is often User.
After that your routes should just work assuming your links are correct. The sign up link alias is...
new_user_registration_path
Your routes.rb should have something like the following in it if it's set up properly...
devise_for :users
In your routes.rb
devise_for :users
maybe try running
rails g devise User
Hopefully you have already run
rails g devise:install

Error Running Ruby on Rails App in Production Mode

I'm just starting to use Ruby on Rails and I am going through a tutorial to get started. I have everything working for testing, so I can use a rails server command in the directory to make it show the basic "Welcome aboard" page that I want to see; however, when I change this to rails server -e production I suddenly only see the "The page you were looking for doesn't exist." page. When this happens, the command prompt shows:
[2013-08-07 19:54:26] INFO WEBrick 1.3.1
[2013-08-07 19:54:26] INFO ruby 1.9.3 (2013-06-27) [i386-mingw32]
[2013-08-07 19:54:26] INFO WEBrick::HTTPServer#start: pid=12664 port=3000
I, [2013-08-07T19:54:26.515238 #12664] INFO -- : Started GET "/" for 127.0.0.1
at 2013-08-07 19:54:26 -0700
F, [2013-08-07T19:54:26.752394 #12664] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/"):
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `c
all'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `ca
ll'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tag
ged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `
call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
This may seem very similar to a number of other questions, but I have tried a number of solutions that have all failed. Thank you for any possible help.
Indeed, this is the default behaviour for an application that has no routes.
The "Welcome aboard" page is just an introduction for developers and is only shown in the development environment.

How is config.assets.debug causing my Rails application to crash?

I've included the arbor-rails gem in my Rails 3.2.8 application and it works fine in development mode, but in production I get the following error:
Started GET "/nullarbor.js" for 127.0.0.1 at 2012-09-20 15:35:23 -0700
ActionController::RoutingError (No route matches [GET] "/nullarbor.js"):
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
thin (1.4.1) lib/thin/connection.rb:80:in `block in pre_process'
thin (1.4.1) lib/thin/connection.rb:78:in `catch'
thin (1.4.1) lib/thin/connection.rb:78:in `pre_process'
thin (1.4.1) lib/thin/connection.rb:53:in `process'
thin (1.4.1) lib/thin/connection.rb:38:in `receive_data'
eventmachine (1.0.0) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.0) lib/eventmachine.rb:187:in `run'
thin (1.4.1) lib/thin/backends/base.rb:63:in `start'
thin (1.4.1) lib/thin/server.rb:159:in `start'
rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
rack (1.4.1) lib/rack/server.rb:265:in `start'
railties (3.2.8) lib/rails/commands/server.rb:70:in `start'
railties (3.2.8) lib/rails/commands.rb:55:in `block in <top (required)>'
railties (3.2.8) lib/rails/commands.rb:50:in `tap'
railties (3.2.8) lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
I've gone through the settings in environments/ and discovered that when I set the following in development.rb:
config.assets.debug = false
I get the error in dev mode, too. And when I set it to true in production it works properly. What could be causing this?
Update: It seems to actually be something to do with the arbor_path function in arbor.js.
arbor.js uses a web worker which means that you need to provide the Worker creation with the appropriate link to where the arbor.js script will be.
What you could do to solve this problem is to provide the absolute path to your arbor.js file instead of letting the code use the arbor_path function that can be messed up by your caching logic or the way you serve js files.
In other words, try to replace
i=new Worker(arbor_path()+"arbor.js");
with
i=new Worker("/final/path/to/arbor.js");
in arbor.js
As #Asimov4 stated, the problem is produced on the following call:
new Worker(arbor_path()+"arbor.js");
Nonetheless, a more elegant solution, compatible with the precompilation of assets, is to change it to:
new Worker("<%= asset_path('arbor.js') %>");
Note: Remember to change the .js file to .js.erb!

No route matches [GET] "/say/hello"

I've written a very small program to help me learn ruby. Below is the error I get from the server logs.
This is the URL I am trying from browser and followed errors: localhost:3000/say/hello
Started GET "/say/hello" for 127.0.0.1 at Sun Jun 10 14:28:45 +0800 2012
ActionController::RoutingError (No route matches [GET] "/say/hello"):
actionpack (3.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.5) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.5) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.5) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.5) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.5) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.5) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.5) lib/rails/engine.rb:479:in `call'
railties (3.2.5) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.5) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.4.1) lib/rack/handler/webrick.rb:13:in `run'
rack (1.4.1) lib/rack/server.rb:265:in `start'
railties (3.2.5) lib/rails/commands/server.rb:70:in `start'
railties (3.2.5) lib/rails/commands.rb:55
railties (3.2.5) lib/rails/commands.rb:50:in `tap'
railties (3.2.5) lib/rails/commands.rb:50
script/rails:6:in `require'
script/rails:6
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.4ms)
This is my Gemfile content
source 'https://rubygems.org'
gem 'rails', '3.2.5'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
I've had a look at a few other SO threads, but none seem to relate specifically to my problem.
In your routes.rb you need either:
match "say/hello" => "myController#myaction" (replacing controller and action with proper values)
or
match ':controller(/:action(/:id))(.:format)' Which will allow you to use code like: link_to "hello", :controller => "mycontroller", :action => "myaction" or enter the URL (like /say/hello)
The former is the preferred method because users cannot go to urls you don't want them to.
Also, your view should be in a subdirectory with the name of the controller that will be using it, not in the actual 'views' directory
EDIT:
Looking at answer below you need to make your file an html.erb not rhtml
Type bundle execute rake routes to list all the routing paths in your application. Check if :controller=>"say", :action=>"hello" there.
Also this doesn't follow the restful rules of rails, so you maybe need to uncomment the match ':controller(/:action(/:id))(.:format)', which at the last line of config/routes.rb.

Rails using mysql2 instead of sqlite3

I have the following configuration:
linux ubuntu 11.04
rails 3.0.9
ruby 1.9.2p290
mysql2 (0.2.7)
I have created first my project using "rails new"
then I have modified the Gemfile to use mysql2 version 0.2.7 (I have read that later versions are working with rails 3.1 only)
Then I changed the file database.yml to use mysql2 instead of sqlite3
But now I'm getting error ActiveRecord::ConnectionNotEstablished when I try to connect to a Controller. Here are the full logs:
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:317:in `retrieve_connection'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
activerecord (3.0.9) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.9) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.9) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.9) lib/rails/application.rb:168:in `call'
railties (3.0.9) lib/rails/application.rb:77:in `send'
railties (3.0.9) lib/rails/application.rb:77:in `method_missing'
railties (3.0.9) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.3) lib/rack/content_length.rb:13:in `call'
rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.3) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.3) lib/rack/server.rb:217:in `start'
railties (3.0.9) lib/rails/commands/server.rb:65:in `start'
railties (3.0.9) lib/rails/commands.rb:30
railties (3.0.9) lib/rails/commands.rb:27:in `tap'
railties (3.0.9) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
PS: I tried almost all solutions provided in this website, but I still have the same issue.
I ended by recreating a new project with the command
rails new -d mysql
And now the pages are retrieved without any problem!
I tried to compare the automatic database.yml file and the manual one, the only diffrence I have noticed was on the user used for mysql database. in the new one the username: root is used.
I came back to the old project and I changed to username/password with root ones I now it is working!!!
I would guess that your database.yml file is incorrect. It should look something like this:
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
If that doesn't work, try changing localhost to 127.0.0.1

Resources