• #6 楼 @kikyous 诶,这样啊。 非常感谢指点!

  • #4 楼 @kikyous 我发现我删掉这行代码就可以了

    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    

    发现,之前我也删掉一行有关 JavaScript 的代码 好像用到 JavaScript 就会抛出错误,这个是为什么?

  • #2 楼 @kikyous 我输入 rake db:reset 抛出错误

    Database 'testblog' does not exist
    testblog already exists
    C:/Users/zmk pc/blog/db/schema.rb doesn't exist yet. Run `rake db:migrate` to c
    eate it, then try again. If you do not intend to use a database, you should ins
    ead alter C:/Users/zmk pc/blog/config/application.rb to limit the frameworks th
    t will be loaded.
    
    

    按照提示我输入 rake db:migrate

    == 20150906003155 CreateArticles: migrating ===================================
    -- create_table(:articles)
       -> 0.0052s
    == 20150906003155 CreateArticles: migrated (0.0052s) ==========================
    
    

    然后重试 rake db:reset

    Database 'testblog' does not exist
    testblog already exists
    -- create_table("articles", {:force=>:cascade})
       -> 1.0321s
    -- initialize_schema_migrations_table()
       -> 0.0360s
    -- create_table("articles", {:force=>:cascade})
       -> 1.0441s
    -- initialize_schema_migrations_table()
       -> 0.0040s
    

    之后我用 rails s 然而还是抛出错误

    ExecJS::ProgramError in Home#index
    Showing C:/Users/zmk pc/blog/app/views/layouts/application.html.erb where line #6 raised:
    
    TypeError: 对象不支持此属性或方法
    Rails.root: C:/Users/zmk pc/blog
    
    Application Trace | Framework Trace | Full Trace
    execjs (2.5.2) lib/execjs/external_runtime.rb:39:in `exec'
    execjs (2.5.2) lib/execjs/external_runtime.rb:21:in `eval'
    execjs (2.5.2) lib/execjs/external_runtime.rb:46:in `call'
    coffee-script (2.4.1) lib/coffee_script.rb:78:in `compile'
    sprockets (3.2.0) lib/sprockets/coffee_script_processor.rb:21:in `block in call'
    sprockets (3.2.0) lib/sprockets/cache.rb:85:in `fetch'
    sprockets (3.2.0) lib/sprockets/coffee_script_processor.rb:20:in `call'
    sprockets (3.2.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
    sprockets (3.2.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
    sprockets (3.2.0) lib/sprockets/processor_utils.rb:56:in `reverse_each'
    sprockets (3.2.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
    sprockets (3.2.0) lib/sprockets/loader.rb:86:in `load_asset_by_uri'
    sprockets (3.2.0) lib/sprockets/loader.rb:45:in `block in load'
    sprockets (3.2.0) lib/sprockets/loader.rb:155:in `fetch_asset_from_dependency_cache'
    sprockets (3.2.0) lib/sprockets/loader.rb:38:in `load'
    sprockets (3.2.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
    sprockets (3.2.0) lib/sprockets/cached_environment.rb:47:in `yield'
    sprockets (3.2.0) lib/sprockets/cached_environment.rb:47:in `load'
    sprockets (3.2.0) lib/sprockets/bundle.rb:23:in `block in call'
    sprockets (3.2.0) lib/sprockets/utils.rb:183:in `dfs'
    sprockets (3.2.0) lib/sprockets/bundle.rb:24:in `call'
    sprockets (3.2.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
    sprockets (3.2.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
    sprockets (3.2.0) lib/sprockets/processor_utils.rb:56:in `reverse_each'
    sprockets (3.2.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
    sprockets (3.2.0) lib/sprockets/loader.rb:86:in `load_asset_by_uri'
    sprockets (3.2.0) lib/sprockets/loader.rb:45:in `block in load'
    sprockets (3.2.0) lib/sprockets/loader.rb:155:in `fetch_asset_from_dependency_cache'
    sprockets (3.2.0) lib/sprockets/loader.rb:38:in `load'
    sprockets (3.2.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
    sprockets (3.2.0) lib/sprockets/cached_environment.rb:47:in `yield'
    sprockets (3.2.0) lib/sprockets/cached_environment.rb:47:in `load'
    sprockets (3.2.0) lib/sprockets/base.rb:63:in `find_asset'
    sprockets (3.2.0) lib/sprockets/environment.rb:30:in `find_asset'
    sprockets (3.2.0) lib/sprockets/base.rb:89:in `[]'
    sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:230:in `lookup_asset_for_path'
    sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:190:in `check_errors_for'
    sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:137:in `block in javascript_include_tag'
    sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:136:in `map'
    sprockets-rails (2.3.2) lib/sprockets/rails/helper.rb:136:in `javascript_include_tag'
    app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__1871698029_64944040'
    actionview (4.2.3) lib/action_view/template.rb:145:in `block in render'
    activesupport (4.2.3) lib/active_support/notifications.rb:166:in `instrument'
    actionview (4.2.3) lib/action_view/template.rb:333:in `instrument'
    actionview (4.2.3) lib/action_view/template.rb:143:in `render'
    actionview (4.2.3) lib/action_view/renderer/template_renderer.rb:66:in `render_with_layout'
    actionview (4.2.3) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
    actionview (4.2.3) lib/action_view/renderer/template_renderer.rb:14:in `render'
    actionview (4.2.3) lib/action_view/renderer/renderer.rb:42:in `render_template'
    actionview (4.2.3) lib/action_view/renderer/renderer.rb:23:in `render'
    actionview (4.2.3) lib/action_view/rendering.rb:100:in `_render_template'
    actionpack (4.2.3) lib/action_controller/metal/streaming.rb:217:in `_render_template'
    actionview (4.2.3) lib/action_view/rendering.rb:83:in `render_to_body'
    actionpack (4.2.3) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
    actionpack (4.2.3) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
    actionpack (4.2.3) lib/abstract_controller/rendering.rb:25:in `render'
    actionpack (4.2.3) lib/action_controller/metal/rendering.rb:16:in `render'
    actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
    activesupport (4.2.3) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
    D:/Ruby21-x64/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
    activesupport (4.2.3) lib/active_support/core_ext/benchmark.rb:12:in `ms'
    actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
    actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
    activerecord (4.2.3) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
    actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:43:in `render'
    actionpack (4.2.3) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
    actionpack (4.2.3) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
    actionpack (4.2.3) lib/abstract_controller/base.rb:198:in `process_action'
    actionpack (4.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
    actionpack (4.2.3) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
    activesupport (4.2.3) lib/active_support/callbacks.rb:115:in `call'
    activesupport (4.2.3) lib/active_support/callbacks.rb:115:in `call'
    activesupport (4.2.3) lib/active_support/callbacks.rb:553:in `block (2 levels) in compile'
    activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
    activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call'
    activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks'
    actionpack (4.2.3) lib/abstract_controller/callbacks.rb:19:in `process_action'
    actionpack (4.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
    actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
    activesupport (4.2.3) lib/active_support/notifications.rb:164:in `block in instrument'
    activesupport (4.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    activesupport (4.2.3) lib/active_support/notifications.rb:164:in `instrument'
    actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
    actionpack (4.2.3) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
    activerecord (4.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
    actionpack (4.2.3) lib/abstract_controller/base.rb:137:in `process'
    actionview (4.2.3) lib/action_view/rendering.rb:30:in `process'
    actionpack (4.2.3) lib/action_controller/metal.rb:196:in `dispatch'
    actionpack (4.2.3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
    actionpack (4.2.3) lib/action_controller/metal.rb:237:in `block in action'
    actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:76:in `call'
    actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
    actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:45:in `serve'
    actionpack (4.2.3) lib/action_dispatch/journey/router.rb:43:in `block in serve'
    actionpack (4.2.3) lib/action_dispatch/journey/router.rb:30:in `each'
    actionpack (4.2.3) lib/action_dispatch/journey/router.rb:30:in `serve'
    actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:821:in `call'
    rack (1.6.4) lib/rack/etag.rb:24:in `call'
    rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
    rack (1.6.4) lib/rack/head.rb:13:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/flash.rb:260:in `call'
    rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
    rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/cookies.rb:560:in `call'
    activerecord (4.2.3) lib/active_record/query_cache.rb:36:in `call'
    activerecord (4.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
    activerecord (4.2.3) lib/active_record/migration.rb:377:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
    activesupport (4.2.3) lib/active_support/callbacks.rb:84:in `run_callbacks'
    actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/reloader.rb:73:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
    web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
    railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
    railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
    activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
    activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
    activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
    railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
    rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
    rack (1.6.4) lib/rack/runtime.rb:18:in `call'
    activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
    rack (1.6.4) lib/rack/lock.rb:17:in `call'
    actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
    rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
    railties (4.2.3) lib/rails/engine.rb:518:in `call'
    railties (4.2.3) lib/rails/application.rb:165:in `call'
    rack (1.6.4) lib/rack/lock.rb:17:in `call'
    rack (1.6.4) lib/rack/content_length.rb:15:in `call'
    rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
    D:/Ruby21-x64/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
    D:/Ruby21-x64/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
    D:/Ruby21-x64/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
    

    \blog\app\views\layouts\application.html.erb 代码如下

    <!DOCTYPE html>
    <html>
    <head>
      <title>Blog</title>
      <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
      <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
      <%= csrf_meta_tags %>
    </head>
    <body>
    
    <%= yield %>
    
    </body>
    </html>
    
    
  • @Kabie 大神,求助!

  • #8 楼 @lyfi2003 哦。可以了。谢谢!

  • #6 楼 @lyfi2003 好快!天哪!谢谢!但又有一个问题冒出来了——tk 无法加载图片 运行 ruby 代码

    ruby C:\AGMK_Teamwork_Link_Manager\root.rb
    

    加载图片的局部代码如下

    @@error_image = TkPhotoImage.new("file" => "image/miku_cry.gif")
         image @@error_image
    

    错误代码如下:

    RuntimeError: couldn't open "image/miku_cry.gif": no such file or directory
    ---< backtrace of Ruby side >-----
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:2054:in `_invoke'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:2054:in `_ip_invoke_core'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:2090:in `_tk_call_core'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:2118:in `tk_call_without_enc'
    D:/Ruby193/lib/ruby/1.9.1/tk/image.rb:81:in `initialize'
    D:/Ruby193/lib/ruby/1.9.1/tk/image.rb:191:in `initialize'
    D:/Ruby193/lib/ruby/1.9.1/tk/image.rb:58:in `block (2 levels) in new'
    <internal:prelude>:10:in `synchronize'
    D:/Ruby193/lib/ruby/1.9.1/tk/image.rb:57:in `block in new'
    D:/Ruby193/lib/ruby/1.9.1/tk/image.rb:56:in `instance_eval'
    D:/Ruby193/lib/ruby/1.9.1/tk/image.rb:56:in `new'
    C:/AGMK_Teamwork_Link_Manager/scripe/enter_atlm.rb:193:in `block in creat_popups_image'
    C:/AGMK_Teamwork_Link_Manager/scripe/enter_atlm.rb:192:in `new'
    C:/AGMK_Teamwork_Link_Manager/scripe/enter_atlm.rb:192:in `creat_popups_image'
    C:/AGMK_Teamwork_Link_Manager/scripe/enter_atlm.rb:146:in `popups'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:1456:in `cb_eval'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:1456:in `eval_cmd'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:1456:in `cb_eval'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:1403:in `call'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:1599:in `block in callback'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:1598:in `catch'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:1598:in `callback'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:1305:in `mainloop'
    D:/Ruby193/lib/ruby/1.9.1/tk.rb:1305:in `block in <module:TkCore>'
    ---< backtrace of Tk side >-------
        invoked from within
    "rb_out c00002"
        invoked from within
    ".w00000.w00003.w00009 invoke"
        ("uplevel" body line 1)
        invoked from within
    "uplevel #0 [list $w invoke]"
        (procedure "tk::ButtonUp" line 24)
        invoked from within
    "tk::ButtonUp .w00000.w00003.w00009"
        (command bound to event)
    
    

    另外,采用您的方法后还是报错

    C:/Users/ADMINI~1/AppData/Local/Temp/ocrC789.tmp/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- scripe/manager.rb (LoadError)
            from C:/Users/ADMINI~1/AppData/Local/Temp/ocrC789.tmp/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
            from C:/Users/ADMINI~1/AppData/Local/Temp/ocrC789.tmp/src/root.rb:8:in `<main>'
    
    

    我用的命令是

    ocra --no-autoload --add-all-core C:\AGMK_Teamwork_Link_Manager\root.rb D:\Ruby193\lib\tcltk C:\AGMK_Teamwork_Link_Manager 
    
  • #3 楼 @lyfi2003 您好,有个问题想请教一下。 我用 require 加载外部的代码块(调用到 Tk 库) (如

    $root_filedir = File.dirname(__FILE__)
    require "#{$root_filedir}/scripe/manager.rb"
    
    

    )怎样才能将它们用 ocra 打包在一起?

  • #3 楼 @lyfi2003 哦!太感谢了!

  • #5 楼 @lyfi2003 哦,这样,谢谢。那么请问一下,怎样才能用 ocra 把 TK 库打包进去?我用 ocra 打包时一直弹错。具体情况 https://ruby-china.org/topics/24199 能否帮忙解决一下,谢谢!

  • #3 楼 @lyfi2003 #! 似乎有时候会对 ocra 起到影响。

  • #1 楼 @Kabie 请问一下要怎么做?谢谢!