【发布时间】:2016-01-12 04:20:32
【问题描述】:
我正在创建一个 Rails 4.2 应用程序以在网页上打印“Hello World”。但是我在运行页面时得到的是这个错误:
未知动作 找不到动作“你好” 应用控制器
这些是我更新的文件:
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
【问题讨论】:
-
您将从这个问题中得到答案。 stackoverflow.com/questions/4778301/…
-
通常你在尾部定义一个新的控制器为
welcome控制器。然后你在route.rb中定义root :to => "welcome#index"。
标签: ruby-on-rails ruby-on-rails-4 railstutorial.org