【问题标题】:Ruby on Rails not recognizing routeRuby on Rails 无法识别路线
【发布时间】:2014-07-26 01:59:43
【问题描述】:

我正在尝试从这里学习 Ruby on Rails:http://guides.rubyonrails.org/getting_started.html,但是当我尝试在第 4.3 节中设置路由的根目录时,虽然路由被识别,但当我运行服务器和本地主机时: 3000,它仍然认为没有根路由。问题可能是什么?我正在使用 Ruby 1.9.3。

【问题讨论】:

  • 请将您的 config/routes.rb 文件添加到您的问题中。
  • 应该是root 'controller#action' Rails 的旧版本是root to: 'controller#action'

标签: ruby-on-rails ruby linux


【解决方案1】:

路线

如果没有您的 routes 文件,甚至没有出现的错误,我只会为您提供使“根”路由正常工作所需的内容:

#config/routes.rb
root "application#index" #-> syntax - "controller#action"

这必须通过适当的控制器操作进行备份:

#app/controllers/application_controller.rb
Class ApplicationController < ActionController::Base
   def index
   end
end

它还需要适当的视图:

#app/views/application/index.html.erb
This is the root page!

【讨论】:

  • root: "application#index" 给出了一个语法错误(这是一个没有大括号的散列)。正如 CWitty 评论的那样,它是 root 'application#index'root to: 'application#index'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-15
  • 2011-10-26
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
相关资源
最近更新 更多