开始使用ruby on rails

时间:2016-06-05 21:52:03

标签: ruby-on-rails ruby

我从来没有用过红宝石,以为我会试一试。安装似乎很好(我认为)。在使用rails server创建服务器并开始设置路由后,问题就出现了,因此新项目将显示而不是ruby欢迎屏幕。它产生的错误是

  

未初始化的常量WelcomeController

我在路由控制器中设置了路径,如此

Rails.application.routes.draw do
root 'welcome#index'

我错过了一步吗?我正在使用installrails.com

中的说明在Windows 7上进行操作

以下是所要求的完整跟踪

  

app / assets / javascripts / application.js:15个链轮(3.6.0)   lib / sprockets / resolve.rb:64:在resolve!' sprockets (3.6.0) lib/sprockets/directive_processor.rb:399:in解析'链轮   (3.6.0)lib / sprockets / directive_processor.rb:207:in   process_require_directive' sprockets (3.6.0) lib/sprockets/directive_processor.rb:180:in阻止   process_directives'链轮(3.6.0)   lib / sprockets / directive_processor.rb:178:在each' sprockets (3.6.0) lib/sprockets/directive_processor.rb:178:in process_directives'   sprockets(3.6.0)lib / sprockets / directive_processor.rb:83:in _call' sprockets (3.6.0) lib/sprockets/directive_processor.rb:68:in call'   sprockets(3.6.0)lib / sprockets / processor_utils.rb:75:in   call_processor' sprockets (3.6.0) lib/sprockets/processor_utils.rb:57:in阻止call_processors'   sprockets(3.6.0)lib / sprockets / processor_utils.rb:56:in   reverse_each' sprockets (3.6.0) lib/sprockets/processor_utils.rb:56:in call_processors'链轮   (3.6.0)lib / sprockets / loader.rb:134:在load_from_unloaded' sprockets (3.6.0) lib/sprockets/loader.rb:60:in块中加载'链轮   (3.6.0)lib / sprockets / loader.rb:317:in   fetch_asset_from_dependency_cache' sprockets (3.6.0) lib/sprockets/loader.rb:44:in负载'链轮(3.6.0)   lib / sprockets / cached_environment.rb:20:in block in initialize' sprockets (3.6.0) lib/sprockets/cached_environment.rb:47:in yield'   sprockets(3.6.0)lib / sprockets / cached_environment.rb:47:in load' sprockets (3.6.0) lib/sprockets/bundle.rb:23:in阻止调用'   sprockets(3.6.0)lib / sprockets / utils.rb:183:在dfs' sprockets (3.6.0) lib/sprockets/bundle.rb:24:in call'链轮(3.6.0)   lib / sprockets / processor_utils.rb:75:在call_processor' sprockets (3.6.0) lib/sprockets/processor_utils.rb:57:in块中   call_processors'链轮(3.6.0)   lib / sprockets / processor_utils.rb:56:在reverse_each' sprockets (3.6.0) lib/sprockets/processor_utils.rb:56:in call_processors'   sprockets(3.6.0)lib / sprockets / loader.rb:134:在load_from_unloaded' sprockets (3.6.0) lib/sprockets/loader.rb:60:in块中加载'   sprockets(3.6.0)lib / sprockets / loader.rb:317:in   fetch_asset_from_dependency_cache' sprockets (3.6.0) lib/sprockets/loader.rb:44:in负载'链轮(3.6.0)   lib / sprockets / cached_environment.rb:20:in block in initialize' sprockets (3.6.0) lib/sprockets/cached_environment.rb:47:in yield'   sprockets(3.6.0)lib / sprockets / cached_environment.rb:47:in load' sprockets (3.6.0) lib/sprockets/base.rb:66:in find_asset'链轮   (3.6.0)lib / sprockets / base.rb:73:在find_all_linked_assets' sprockets (3.6.0) lib/sprockets/manifest.rb:142:in块中查找'链轮   (3.6.0)lib / sprockets / legacy.rb:114:在stat_tree中的block (2 levels) in logical_paths' sprockets (3.6.0) lib/sprockets/path_utils.rb:223:in 块中'链轮(3.6.0)   lib / sprockets / path_utils.rb:207:block in stat_directory' sprockets (3.6.0) lib/sprockets/path_utils.rb:204:in每个'链轮(3.6.0)   lib / sprockets / path_utils.rb:204:stat_directory' sprockets (3.6.0) lib/sprockets/path_utils.rb:222:in stat_tree'链轮(3.6.0)   lib / sprockets / legacy.rb:105:在logical_paths中的each' sprockets (3.6.0) lib/sprockets/legacy.rb:105:in块中'链轮   (3.6.0)lib / sprockets / legacy.rb:104:在each' sprockets (3.6.0) lib/sprockets/legacy.rb:104:in logical_paths'链轮(3.6.0)   lib / sprockets / manifest.rb:140:find' sprockets-rails (3.0.4) lib/sprockets/railtie.rb:49:in每个'链轮导轨(3.0.4)   lib / sprockets / railtie.rb:49:in map' sprockets-rails (3.0.4) lib/sprockets/railtie.rb:49:in precompiled_assets'链轮护栏   (3.0.4)lib / sprockets / railtie.rb:34:在asset_precompiled?' sprockets-rails (3.0.4) lib/sprockets/railtie.rb:214:in块中(3   在'链轮导轨(3.0.4)   lib / sprockets / rails / helper.rb:345:在call' sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:345:in预编译?'链轮护栏   (3.0.4)lib / sprockets / rails / helper.rb:349:in   raise_unless_precompiled_asset' sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:334:in find_debug_asset'   sprockets-rails(3.0.4)lib / sprockets / rails / helper.rb:216:在{_ 1}}块中的resolve_asset'   sprockets-rails(3.0.4)lib / sprockets / rails / helper.rb:228:in block in lookup_debug_asset' sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:229:in detect'   sprockets-rails(3.0.4)lib / sprockets / rails / helper.rb:228:in   each' sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:228:in lookup_debug_asset'   sprockets-rails(3.0.4)lib / sprockets / rails / helper.rb:157:在resolve_asset' sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:215:in map'链轮导轨(3.0.4)   lib / sprockets / rails / helper.rb:156:在block in stylesheet_link_tag' sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:156:in _ app_views_layouts_application_html_erb__347772551_45585852'   actionview(4.2.6)lib / action_view / template.rb:145:在stylesheet_link_tag' app/views/layouts/application.html.erb:5:in 工具'的ActionView   (4.2.6)lib / action_view / template.rb:333:在block in render' activesupport (4.2.6) lib/active_support/notifications.rb:166:in渲染' actionview(4.2.6)   LIB / ACTION_VIEW /渲染器/ template_renderer.rb:66:在   instrument' actionview (4.2.6) lib/action_view/template.rb:143:in render_template'   actionview(4.2.6)lib / action_view / renderer / template_renderer.rb:14:in   render_with_layout' actionview (4.2.6) lib/action_view/renderer/template_renderer.rb:52:in render_template' actionview(4.2.6)   lib / action_view / renderer / renderer.rb:27:在render' actionview (4.2.6) lib/action_view/renderer/renderer.rb:46:in _ render_template' ActionPack的   (4.2.6)lib / action_controller / metal / streaming.rb:217:in   render' actionview (4.2.6) lib/action_view/rendering.rb:100:in render_to_body' actionpack(4.2.6)   lib / action_controller / metal / rendering.rb:32:在_render_template' actionview (4.2.6) lib/action_view/rendering.rb:83:in render_to_body' actionpack(4.2.6)   lib / abstract_controller / rendering.rb:25:in render_to_body' actionpack (4.2.6) lib/action_controller/metal/renderers.rb:37:in render' ActionPack的   (4.2.6)lib / action_controller / metal / instrumentation.rb:44:在render' actionpack (4.2.6) lib/action_controller/metal/rendering.rb:16:in块中的ms'   C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/benchmark.rb:303:在   block (2 levels) in render' activesupport (4.2.6) lib/active_support/core_ext/benchmark.rb:12:in MS' actionpack(4.2.6)   lib / action_controller / metal / instrumentation.rb:44:在realtime' activesupport (4.2.6) lib/active_support/core_ext/benchmark.rb:12:in cleanup_view_runtime' activerecord(4.2.6)   LIB / active_record / railties / controller_runtime.rb:25:在   block in render' actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:87:in 渲染'   actionpack(4.2.6)   lib / action_controller / metal / implicit_render.rb:10:在cleanup_view_runtime' actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:43:in send_action' actionpack(4.2.6)   lib / abstract_controller / base.rb:198:在default_render' actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:5:in process_action' actionpack(4.2.6)   lib / abstract_controller / callbacks.rb:20:in process_action' actionpack (4.2.6) lib/action_controller/metal/rendering.rb:10:in call'   activesupport(4.2.6)lib / active_support / callbacks.rb:117:在block in process_action' activesupport (4.2.6) lib/active_support/callbacks.rb:117:in块中(2)   在编译中#level; activesupport(4.2.6)   lib / active_support / callbacks.rb:505:call' activesupport (4.2.6) lib/active_support/callbacks.rb:555:in来电' activesupport(4.2.6)   lib / active_support / callbacks.rb:92:在call' activesupport (4.2.6) lib/active_support/callbacks.rb:505:in _ run_process_action_callbacks' activesupport(4.2.6)   lib / active_support / callbacks.rb:81:在__run_callbacks__' activesupport (4.2.6) lib/active_support/callbacks.rb:778:in process_action'   actionpack(4.2.6)lib / action_controller / metal / rescue.rb:29:in   run_callbacks' actionpack (4.2.6) lib/abstract_controller/callbacks.rb:19:in阻止   process_action' activesupport(4.2.6)   lib / active_support / notifications.rb:164:in process_action' actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:32:in instrument'   activesupport(4.2.6)lib / active_support / notifications.rb:164:in   block in instrument' activesupport (4.2.6) lib/active_support/notifications/instrumenter.rb:20:in process_action'   actionpack(4.2.6)   lib / action_controller / metal / params_wrapper.rb:250:在instrument' actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack(4.2.6)   lib / abstract_controller / base.rb:137:在process_action' activerecord (4.2.6) lib/active_record/railties/controller_runtime.rb:18:in 进程' actionpack(4.2.6)   lib / action_controller / metal.rb:196:在process' actionview (4.2.6) lib/action_view/rendering.rb:30:in发送'   actionpack(4.2.6)lib / action_controller / metal.rb:237:dispatch' actionpack (4.2.6) lib/action_controller/metal/rack_delegation.rb:13:in来电' ActionPack的   (4.2.6)lib / action_dispatch / routing / route_set.rb:74:in block in action' actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:74:in serve' actionpack(4.2.6)lib / action_dispatch / journey / router.rb:43:in   dispatch' actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:43:in 各' actionpack(4.2.6)   lib / action_dispatch / journey / router.rb:30:在block in serve' actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in来电'机架(1.6.4)   lib / rack / etag.rb:24:in serve' actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:in来电'机架(1.6.4)   lib / rack / head.rb:13:in call' rack (1.6.4) lib/rack/conditionalget.rb:25:in来电'   actionpack(4.2.6)lib / action_dispatch / middleware / flash.rb:260:in   call' actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in上下文'   rack(1.6.4)lib / rack / session / abstract / id.rb:220:in call' rack (1.6.4) lib/rack/session/abstract/id.rb:225:in call'   activerecord(4.2.6)lib / active_record / query_cache.rb:36:in call' actionpack (4.2.6) lib/action_dispatch/middleware/cookies.rb:560:in call' activerecord(4.2.6)lib / active_record / migration.rb:377:in   call' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in 阻止通话'   activesupport(4.2.6)lib / active_support / callbacks.rb:88:in   call' actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:in _ run_call_callbacks'   activesupport(4.2.6)lib / active_support / callbacks.rb:81:in   __run_callbacks__' activesupport (4.2.6) lib/active_support/callbacks.rb:778:in呼叫' ActionPack的   (4.2.6)lib / action_dispatch / middleware / reloader.rb:73:in run_callbacks' actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in call' actionpack(4.2.6)   lib / action_dispatch / middleware / debug_exceptions.rb:17:在call' actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in 块中   叫' web-console(2.3.0)lib / web_console / middleware.rb:18:in call' web-console (2.3.0) lib/web_console/middleware.rb:28:in call'   actionpack(4.2.6)   lib / action_dispatch / middleware / show_exceptions.rb:30:in catch' web-console (2.3.0) lib/web_console/middleware.rb:18:in call_app' railties   (4.2.6)lib / rails / rack / logger.rb:20:在call' railties (4.2.6) lib/rails/rack/logger.rb:38:in块中标记为'   activesupport(4.2.6)lib / active_support / tagged_logging.rb:26:in   block in call' activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in标记'铁路(4.2.6)   lib / rails / rack / logger.rb:20:in tagged' activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in来电'机架(1.6.4)   lib / rack / methodoverride.rb:22:在call' actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in电话' activesupport(4.2.6)   LIB / active_support /缓存/策略/ local_cache_middleware.rb:28:在   call' rack (1.6.4) lib/rack/runtime.rb:18:in呼叫' actionpack(4.2.6)   lib / action_dispatch / middleware / static.rb:120:在call' rack (1.6.4) lib/rack/lock.rb:17:in电话'铁路(4.2.6)   lib / rails / engine.rb:518:在call' rack (1.6.4) lib/rack/sendfile.rb:113:in来电'机架(1.6.4)   lib / rack / lock.rb:17:in call' railties (4.2.6) lib/rails/application.rb:165:in来电'机架(1.6.4)   lib / rack / handler / webrick.rb:88:in call' rack (1.6.4) lib/rack/content_length.rb:15:in service'   C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:在   {_ 1}}阻止了start_thread'

2 个答案:

答案 0 :(得分:3)

此错误可能是由于welcome_controller.rb中缺少定义WelcomeController的{​​{1}}文件造成的。

此文档可能有助于您入门: http://guides.rubyonrails.org/action_controller_overview.html#controller-naming-convention

答案 1 :(得分:2)

Rails使用了许多约定,例如,路由引用welcome#index将引用名为WelcomeController的控制器并调用名为index的方法。

你必须像这样创建一个控制器app/controllers/welcome_controller.rb

class WelcomeController < ApplicationController
  def index
    render text:"hello world!"
  end
end

现在你将能够看到“hellow world!”根目录中的文字。

您还可以使用生成器创建在终端中执行的控制器:rails generate controller welcome index

另一个约定是没有渲染的控制器方法索引将传递视图app/views/welcome/index.html.erb

在本指南中查看有关渲染的详情:layouts and rendering