Tôi có một số đường ray 3.1 ứng dụng và tôi đang gặp sự cố này trong tất cả các ứng dụng này.Các tệp JS được bao gồm trong ứng dụng đường ray
Tôi có một loạt tệp js được đưa vào tệp application.js của mình. Dưới đây là application.js tôi:
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_self
//= require_tree .
Vấn đề là khi nào, development.rb, tôi đã config.assets.debug thiết lập là true, tất cả các tập tin javascript tôi có được đôi bao gồm trong tiêu đề. Trên thực tế, chúng không được bao gồm một cách rõ ràng, nhưng chúng được bao gồm một lần riêng lẻ và một lần như là một phần của tệp application.js đã biên dịch. Thẻ js bao gồm các thẻ như sau:
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<script src="/assets/animation_elements.js?body=1" type="text/javascript"></script>
<script src="/assets/categories.js?body=1" type="text/javascript"></script>
<script src="/assets/facebox.js?body=1" type="text/javascript"></script>
…
Vậy cái quái gì? Kết quả của việc này là các hành vi JQuery onClick() khác nhau đang được thực hiện hai lần và vô nghĩa khác. vấn đề ở đây là gì? Đối với hồ sơ, sau đây là toàn bộ tập tin development.rb tôi:
Geobooks::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 webserver 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_view.debug_rjs = 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
#for devise
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = false
end
Bạn hoàn toàn đúng rằng các tệp js được biên dịch vào tệp application.js, nhưng tôi đã biết điều đó. Tôi biên dịch trước tài sản của mình trước khi đẩy ứng dụng của tôi lên heroku. Âm thanh như tôi nên xóa các tài sản biên dịch trước của tôi, gitIgnore manifest.yml, và để cho heroku xử lý biên dịch trước. Tôi sẽ thử xem. – CharlieMezak
@CharlieMezak đã làm việc đó? –