I'm creating a Rails 4.2 app to print "Hello World" on a web page. But what I get while running the page is this error:
Unknown action The action 'hello' could not be found for ApplicationController
These are the files I updated:
application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
def hello
render text: "hello, world!"
end
end
routes.rb
Rails.application.routes.draw do
# You can have the root of your site routed with "root"
root 'application#hello'
end
If you're using cloud9 and following the tutorial at www.railstutorial.org. Then you probably have the code right. You just need to push the "run" button at top center in your dev environment. Hint, it's green.
This detail is omitted in the tutorial but by appearance, the edits you make in the ide aren't saved until you click "run". Seems like a pretty low bar to clear on one's own but it took me hours of google and self-doubt. So try that.
Use this way.
Rails.application.routes.draw do
root to: 'application#hello'
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With