表示する投稿が他にもある場合にユーザーが下にスクロールし続けるために使用する「エンドレススクロール」機能を実装しました。私はRailscastsをフォローしましたが、ローカルでうまく機能します(javascriptとwill-paginate gem)。ただし、サーバーでは、この機能は機能していません。表示されるのは単純なページネーションだけで、エンドレス スクロールは適用されません。ローカルでjavascriptがうまく動いているので、コンパイルや前処理に関係していると思います。
bundle exec rake assets:precompile
ローカルで実行してデプロイしようとしました。また、サーバーでも同じコマンドを実行してみました。問題はまだ解決されていません。
誰かが問題の良い説明を持っていますか? 関連ファイルは次の場所にあります。
- app/assets/javascripts/posts.js.coffee
- アプリ/ビュー/index.js.erb
この機能はローカル サーバー上で十分に機能するため、js ファイルの内容は問題ないと仮定します。問題の原因はコンパイルにあるとほぼ確信しています。
アップデート:
アセット パイプラインに関する 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.
これは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.
そしてGemfileでは、私は持っています
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
これは、app/assets/javascripts/posts.js.coffeeファイルがデプロイ前に適切にコンパイルされておらず、それが問題だったということですか?
どうぞよろしくお願いいたします。