2012-02-05 35 views
7

Tôi cố gắng nâng cấp ứng dụng của mình từ đường ray 3.1.3 lên đường 3.2.1 và tôi gặp sự cố với nội dung.Nâng cấp từ đường ray 3.1.3 lên đường ray 3.2.1. Lỗi với nội dung

tôi có loại lỗi:

ActionController::RoutingError (No route matches [GET] "/assets/logos/opera_logo.png"): 
    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' 
    /usr/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service' 
    /usr/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run' 
    /usr/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread' 

Rails không tìm thấy toàn bộ tài sản của tôi, nhưng tôi nghĩ hơn là vào đúng thư mục (ứng dụng/tài sản/images/logo/ví dụ).

Tôi đã làm theo hướng dẫn này để nâng cấp hệ thống của tôi: http://railscasts.com/episodes/318-upgrading-to-rails-3-2?view=asciicast. Nó đang chạy rất tốt với đường ray 3.1. Tôi không tìm thấy bất kỳ thay đổi nào khác để làm. Tôi có thể làm gì?

Đây là Gemfile tôi:

source 'http://rubygems.org' 

gem 'rails', '3.2.1' 

# Bundle edge Rails instead: 
# gem 'rails',  :git => 'git://github.com/rails/rails.git' 

gem 'sqlite3' 


# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 
    gem 'uglifier', '>= 1.0.3' 
end 

gem 'jquery-rails' 

# To use ActiveModel has_secure_password 
# gem 'bcrypt-ruby', '~> 3.0.0' 

# Use unicorn as the web server 
# gem 'unicorn' 

# Deploy with Capistrano 
# gem 'capistrano' 

# To use debugger 
gem 'ruby-debug19', :require => 'ruby-debug' 

group :test do 
    gem 'capybara', '1.1.2' 
    gem 'rspec-rails', '2.8.1' 
    gem 'autotest-rails', '4.1.1' 
    gem 'spork', '0.8.5' 
    gem 'factory_girl_rails', '1.4.0' 
    gem 'email_spec', '1.2.1' 
    gem 'cucumber-rails', '1.2.1' 
    gem 'launchy', '2.0.5' 
    gem 'pickle', '0.4.10' 
    gem 'database_cleaner', '0.7.0' 
    gem 'simplecov', '0.5.4' 
    gem 'simplecov-rcov', '0.2.3' 
    gem "mocha", '0.10.0' 
    gem 'capybara-firebug', '0.0.10' 
    gem "prawn", '0.8.4' 
end 

group :development do 
    gem "nifty-generators", '0.4.6' 
end 

gem 'active_reload', '0.6.1' 
gem "galetahub-simple_captcha", '0.1.3', :require => "simple_captcha" 
gem 'authlogic', '3.1.0' 
gem 'meta_search', '1.1.3' 
gem 'naive_bayes', :git => 'git://github.com/reddavis/Naive-Bayes.git' 

Đây là development.rb tôi:

Onopia::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 

    # Raise exception on mass assignment protection for Active Record models 
    config.active_record.mass_assignment_sanitizer = :strict 

    # Log the query plan for queries taking more than this (works 
    # with SQLite, MySQL, and PostgreSQL) 
    config.active_record.auto_explain_threshold_in_seconds = 0.5 
end 

Và đây là application.rb tôi:

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

# Pick the frameworks you want: 
require "active_record/railtie" 
require "action_controller/railtie" 
require "action_mailer/railtie" 
require "active_resource/railtie" 
require "sprockets/railtie" 
# require "rails/test_unit/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 Onopia 
    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 = :fr 

    # 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' 

    # Configure generators values. Many other options are available, 
    # be sure to check the documentation. 
    #config.generators do |g| 
    # g.test_framework :rspec, :fixture => false 
    #end 

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

Edit: một ví dụ tốt hơn .

Tôi muốn xem tập tin này:

ứng dụng/tài sản/Javascripts/application.js

Khi tôi đi đến url này:

http://localhost:3000/assets/application.js

Và tôi gặp lỗi này:

Started GET "/assets/application.js" for 127.0.0.1 at 2012-02-06 17:04:38 -0500 
Served asset /application.js - 404 Not Found (1ms) 

ActionController::RoutingError (No route matches [GET] "/assets/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' 
    /usr/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service' 
    /usr/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run' 
    /usr/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread' 

Cảm ơn rất nhiều và có một ngày tốt đẹp.

+0

Bạn nói nội dung nằm trong 'ứng dụng/nội dung/hình ảnh', nhưng bạn đang gọi hình ảnh từ 'app/assets/logos' –

+0

Xin lỗi, đó là lỗi của tôi. Tệp của tôi ở đây: app/assets/images/logos/opera_logo.png. Tôi đã chỉnh sửa bài đăng của mình. – Dougui

+0

Tôi tự hỏi nếu việc chỉnh sửa bài đăng có thay đổi thông báo RoutingError không. Theo nhật ký của bạn phía trên hình ảnh bạn tham chiếu không có trong thư mục 'asset/images', nhưng trong' asset/logos'. Thay đổi vị trí tệp của bạn thành 'asset/logos' hoặc tìm liên kết giới thiệu tốt hơn và thay đổi nó thành' asset/images/opera_logo.png' –

Trả lời

2

Dường như một số phụ thuộc đá quý bị hỏng và bundle exec rails server nên phân giải e cái này Điều này sẽ được chạy mà không cần sudo ... trừ khi bạn thường làm việc với ứng dụng của mình với các đặc quyền root (điều này không tốt). Kiểm tra quyền truy cập tệp/thư mục trong thư mục gốc của thư mục, có thể đã bị hỏng bằng cách lạm dụng các lệnh sudo trước đó. Trong khi phát triển, bạn hầu như không cần bất kỳ đặc quyền root nào.

Ngoài ra, similar issues cũng đã xuất hiện trước đó và câu trả lời là cập nhật toàn bộ gemset của bạn, chủ yếu là sprockets và ray. Các tệp cấu hình của bạn trông ổn với tôi và tôi không thể tạo lại lỗi.

Nếu điều đó không giúp ích được, tôi sẽ tạo ứng dụng đường ray mới, kiểm tra đường dẫn tài sản đang hoạt động ở đó với cùng một gemset mà bạn có và kiểm tra chéo tất cả các tệp cấu hình theo cách thủ công.

Có nhiều công cụ gỡ lỗi khác nhau để định tuyến quá, nhưng hãy thử ở trên trước.

+0

Tôi đã cài đặt một tập hợp đá quý mới, với RVM, và nó hoạt động! Cảm ơn rất nhiều. – Dougui

+0

Tôi bắt đầu máy chủ đường ray với 'bó exec rails s' và nó hoạt động. Điều strage về lỗi này là các tài sản khác (javascripts, stylesheets) làm việc tốt với 'rails s' nhưng hình ảnh thì không. –

+0

@Giovanni Bạn đang đưa ra quá ít chi tiết để hiểu. Hãy bắt đầu một câu hỏi mới giải thích tình huống của bạn. Hãy chắc chắn bao gồm 'Gemfile' của bạn và gọi đến các tài sản hình ảnh không hoạt động và các thông báo lỗi đầy đủ. –

0

Tôi đã gặp phải điều tương tự trước đó. Bạn tham khảo chúng như thế nào? Nó là một thất bại image_tag hoặc tham chiếu CSS không?

Nếu tệp của bạn ở đây /app/assets/images/logos/opera_logo.png thì các tham chiếu sau sẽ hoạt động.

Từ một tập tin html.erb: <%= image_tag('logos/opera_logo.png') %>

Từ một tập tin SCSS: background: url(image_path("logos/opera_logo.png"))

http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

+0

Đó chính xác là suy nghĩ tương tự. – Dougui

+0

Tôi đã thử với <% = image_tag ('logo/opera_logo.png')%>. – Dougui

13

Tôi gặp sự cố tương tự mà tôi đã giải quyết bằng cách xóa đá quý active_reload.

+0

Điều đó đã sửa nó cho tôi. Cảm ơn! – zaius

+1

Đây là một vấn đề đối với Rails <3.2 dự án lên tới 3.2+ ... trang chủ của dự án nói rằng 'active_reload' không tương thích với Rails 3.2 trong tương lai. –

+0

Sau vài giờ tìm kiếm - tôi đã được tìm thấy. Cảm ơn rất nhiều! –

0

Mới đối với Rails, nhưng đối với hình ảnh của tôi nằm trong thư mục ../app/assets/images ví dụ: "rails.png" tham chiếu CSS thích hợp cho hình nền là: background: white url(rails.png) repeat-y; (tùy chọn được hiển thị)

Mặc dù nó nằm trong thư mục hình ảnh, với đường ray 3.2.6 (phiên bản tôi đang sử dụng), bạn không ' Đặt phần hình ảnh của thư mục.

Các vấn đề liên quan