zauzaj
zauzaj

Reputation: 1226

Include javascript on specific pages using Rails 3

I have created service for live chat using Ajax and Rails, where I send ajax GET requests to server and receive responds . Anyway, I want that Ajax script works on every page except on home/chat. So, I have chat.js file and I include it in application.html like follow:

title Online Mental Health
 = stylesheet_link_tag 'application', :media => "all"
 = csrf_meta_tags
 = javascript_include_tag 'application'
 - unless params[:controller] == 'home' 
   = javascript_include_tag 'chat.js' 

Also, I added in staging.rb and production.rb this :

 config.assets.precompile += %w( chat.js )

And I didn't include my chat.js file into application.js .

But when I deploy my application on server, and do

 RAILS_ENV=staging bundle exex rake assets:precompile

I am getting error as bellow:

Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Dashboards#user_view

chat.js isn't precompiled

Extracted source (around line #10):

7:     / = render 'shared/chat_javascript_include'
8:     = javascript_include_tag 'application'
9:     - unless params[:controller] == 'home' 
10:       = javascript_include_tag 'chat.js' 
11:   body
12:     = render 'forum_areas/header'
13:   - if current_user.present?

Any help is appreciated. Thanks

Upvotes: 0

Views: 42

Answers (1)

Rajarshi Das
Rajarshi Das

Reputation: 12320

I make my comment as a post for any one use it

Please do this in your environment file(staging.rb , production.rb)

config.assets.compile = true

Upvotes: 1

Related Questions