2012-02-20 238 views
0

我剛剛更新到Rails 3.2,我開始變得象這樣的錯誤:RoutingError在JavaScript文件夾從Rails的3.1升級後到Rails 3.2

Started GET "/javascripts/application.js?body=1" for 127.0.0.1 at 2012-02-20 23:25:10 +0800 

ActionController::RoutingError (No route matches [GET] "/javascripts/application.js"): 
    actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
    actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
    railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app' 
    railties (3.2.1) lib/rails/rack/logger.rb:16:in `call' 
    actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call' 
    rack (1.4.1) lib/rack/methodoverride.rb:21:in `call' 
    rack (1.4.1) lib/rack/runtime.rb:17:in `call' 
    activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
    rack (1.4.1) lib/rack/lock.rb:15:in `call' 
    actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call' 
    railties (3.2.1) lib/rails/engine.rb:479:in `call' 
    railties (3.2.1) lib/rails/application.rb:220:in `call' 
    rack (1.4.1) lib/rack/content_length.rb:14:in `call' 
    railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call' 
    rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service' 
    /home/alex/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service' 
    /home/alex/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run' 
    /home/alex/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread' 


    Rendered /home/alex/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.8ms) 

同爲post.js,page.js等。但所有這些文件都在assets/javascripts文件夾中。

我究竟有什麼才能解決這個問題呢?

這是我多麼包括他們:

<%= javascript_include_tag "application" %> 

application.rb中:

require File.expand_path('../boot', __FILE__) 

require 'rails/all' 

require "sprockets/railtie" 

if defined?(Bundler) 
    # If you precompile assets before deploying to production, use this line 
    Bundler.require(*Rails.groups(:assets => %w(development test))) 
    # If you want your assets lazily compiled in production, use this line 
    # Bundler.require(:default, :assets, Rails.env) 
end 

module Sandbox3Devise 
    class Application < Rails::Application 
    # Settings in config/environments/* take precedence over those specified here. 
    # Application configuration should go into files in config/initializers 
    # -- all .rb files in that directory are automatically loaded. 

    # Custom directories with classes and modules you want to be autoloadable. 
    # config.autoload_paths += %W(#{config.root}/extras) 

    # Only load the plugins named here, in the order given (default is alphabetical). 
    # :all can be used as a placeholder for all plugins not explicitly named. 
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 

    # Activate observers that should always be running. 
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 
    # config.time_zone = 'Central Time (US & Canada)' 

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 
    # config.i18n.default_locale = :de 

    # Configure the default encoding used in templates for Ruby 1.9. 
    config.encoding = "utf-8" 

    # Configure sensitive parameters which will be filtered from the log file. 
    config.filter_parameters += [:password] 

    # Enable the asset pipeline 
    config.assets.enabled = true 

    # Version of your assets, change this if you want to expire all your assets 
    config.assets.version = '1.0' 
    end 
end 

development.rb:

Sandbox3Devise::Application.configure do 
    # Settings specified here will take precedence over those in config/application.rb 

    # In the development environment your application's code is reloaded on 
    # every request. This slows down response time but is perfect for development 
    # since you don't have to restart the web server when you make code changes. 
    config.cache_classes = false 

    # Log error messages when you accidentally call methods on nil. 
    config.whiny_nils = true 

    # Show full error reports and disable caching 
    config.consider_all_requests_local  = true 
    config.action_controller.perform_caching = false 

    # Don't care if the mailer can't send 
    config.action_mailer.raise_delivery_errors = false 

    # Print deprecation notices to the Rails logger 
    config.active_support.deprecation = :log 

    # Only use best-standards-support built into browsers 
    config.action_dispatch.best_standards_support = :builtin 

    # Do not compress assets 
    config.assets.compress = false 

    # Expands the lines which load the assets 
    config.assets.debug = true 

    config.action_mailer.default_url_options = { :host => 'localhost:3000' } 
end 

回答

4

哪個版本做了你升級? Rails 3.1引入了asset pipeline,這是一種組織資產(圖像,樣式表,JavaScript等等)的新方法。似乎你必須進行轉換:上面鏈接的指南是一個很好的開始。

**在config/application.rb,是線require "sprockets/railtie"本?如果沒有,你應該添加它。

* *(第二編輯):因此,而不是javascripts/application.js?body=1,您應該有assets/application.js?body=1。這可以使用config.assets.prefix = "/some_other_path"進行設置。它看起來並沒有在你粘貼的文件中被改變,所以這可能仍然不是,在這種情況下,我放棄了。 :P

+0

我從Rails 3.1升級了 – alexchenco 2012-02-20 15:47:11

+0

我有一個想法,請參閱編輯 – ksol 2012-02-20 15:52:25

+0

謝謝,我補充說,但同樣的問題:( – alexchenco 2012-02-20 16:00:12

0

對不起,回答到這個老問題,這主要是針對那些(像我一樣),誰都會碰到這個線程絆倒的利益。

我也有這個問題。我沒有升級,我開始我的應用程序作爲rails3應用程序,過了一段時間,發生這種問題。我認爲原因是我開始搞亂gem,比如Faye,bootstrap-wysihtml5等,它們需要在application.js和applicaion.css文件中使用jquery引用。 (這就是它出現在我的版本控制日誌)

總之,要解決這個問題,我剛剛創建了一個新的Rails應用程序和複製的應用程序,配置,DB和寶石了。這解決了rails服務器記錄的每一個問題,所以它可能是資產管道的一個缺陷。如上所示,我還在application.rb中包含了require "sprockets/railtie"這一行。

相關問題