[英]Coffeescript/Javascript Is Not Working on Server
I've implemented 'endless scrolling' feature, which users use to keep scrolling down if there are more posts to show. 我已经实现了“无限滚动”功能,如果有更多帖子要显示,用户可以使用该功能持续向下滚动。 I followed Railscasts, and it works great locally (javascripts and will-paginate gem).
我遵循了Railscasts,在本地效果很好(javascript和will-paginate gem)。 However, on the server, this feature is not working.
但是,在服务器上,此功能不起作用。 All I see is simple pagination, and endless scrolling is not applied.
我所看到的只是简单的分页,并且没有应用无限滚动。 I think it's related to compiling or preprocessing because javascript is working fine locally.
我认为这与编译或预处理有关,因为javascript在本地运行良好。
I've tried running bundle exec rake assets:precompile
locally, and deploying it. 我试过运行
bundle exec rake assets:precompile
在本地bundle exec rake assets:precompile
并部署它。 Also, I tried running the same command on the server as well. 另外,我也尝试在服务器上运行相同的命令。 The problem hasn't been solved yet.
该问题尚未解决。
Does anybody have a good explanation for the problem? 有人对这个问题有很好的解释吗? Related files are located as follows:
相关文件位于以下位置:
Assume the contents in the js files are fine because the feature works greatly on the local server. 假定js文件中的内容很好,因为该功能在本地服务器上可以很好地工作。 I am almost sure that the source of problem is compilation.
我几乎可以确定问题的根源是编译。
UPDATE: 更新:
from Rails guide about assets pipeline http://guides.rubyonrails.org/asset_pipeline.html 从Rails指南中获取有关资产管道的信息http://guides.rubyonrails.org/asset_pipeline.html
When these files(coffescripts) are requested, they are processed by the processors provided
by the coffee-script and sass gems and then sent back to the browser
as JavaScript and CSS respectively.
This explains about the line in config/application.rb 这说明了config / application.rb中的这一行
Bundler.require *Rails.groups(:assets => %w(development test))
only loads gems from the assets group in your development and test environment.
This means that things like sass-rails and uglifier won't be available
in production, which then means that you won't be able to properly
compile/minify/whatever your assets on the fly in production
if you're making use of those gems.
and in Gemfile, I have 在Gemfile中,我有
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
Does this mean that app/assets/javascripts/posts.js.coffee file wasn't compiled properly before being deployed and that was the problem? 这是否意味着app / assets / javascripts / posts.js.coffee文件在部署之前未正确编译,这就是问题所在?
Thank you very much in advance for your kind help. 预先非常感谢您的帮助。
If this happens, try the followings: 如果发生这种情况,请尝试以下操作:
rm -rf public/assets
rm -rf public/assets
press ctrl+F5 or delete your browser history manually
press ctrl+F5 or delete your browser history manually
a. cap deploy:restart (in your local terminal) AND b. sudo service nginx restart (in your server)
a. cap deploy:restart (in your local terminal) AND b. sudo service nginx restart (in your server)
a. cap deploy:restart (in your local terminal) AND b. sudo service nginx restart (in your server)
cap deploy
Trying to solve the problem, I learned: 为了解决这个问题,我了解到:
bundle exec rake assets:precompile
bundle exec rake assets:precompile
Read the following documents to understand better about the asset pipeline: 阅读以下文档以更好地了解资产管道:
Rails/Bundler precompile vs lazy compile Rails / Bundler预编译与延迟编译
http://guides.rubyonrails.org/asset_pipeline.html http://guides.rubyonrails.org/asset_pipeline.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.