我遵循ruby on rails教程指南,但我一直有我的标题中所述的错误。我完全不知道它为什么会出现。
routes.rb
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root ‘application#hello’
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
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”
end
end
请给我建议,因为我一直在尝试,甚至重新安装一切基于Ruby on Rails教程。
问题在这一行root ‘application#hello’
。看起来您的系统对单引号使用了错误的符号(您正在使用的是8216 unicode字符,您应该使用39)。同样在你的控制器render text: “Hello”
会抛出一个错误。
应该是root 'application#hello'
和render text: "Hello"
这可以在您的系统键盘设置中更改。不能更准确,因为我不知道你使用的是什么系统,但问题肯定是单引号的符号错误。