Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action defined in ApplicationController can not be found

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
like image 829
Sara Taha Avatar asked Apr 29 '26 08:04

Sara Taha


2 Answers

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.

like image 126
gold2th Avatar answered May 01 '26 20:05

gold2th


Use this way.

Rails.application.routes.draw do
  root to: 'application#hello'
end
like image 32
Gupta Avatar answered May 01 '26 20:05

Gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!