Resolve stylesheet_link_tag fails to work in Ruby on Rails

  sonic0002        2016-10-14 03:59:11       10,440        2    

When developing Ruby On Rails application, developers sometimes will see an unexpected behavior where the application cannot be loaded due to "TypeError: Object doesn't support this property or method" when invoking stylesheet_link_tag. The symptom looks like

 And the Rails log will show something similar to below

The error occurs because there is some problem finding the correct assets which are located in app/assets. To resolve the issue, you can following below steps.

  1. Add gem 'coffee-script-source', '1.8.0' into Gemfile and run bundle install then
  2. Run bundle update coffee-script-source
  3. Restart rails server

Or there is a dirty workaround which is to change the code from

<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>

to

<%= stylesheet_link_tag "default", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "default", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>

But note this workaround doesn't really resolve the application issue, it just makes your application works without expected stylesheets and javascripts.

RUBY ON RAILS  STYLESHEET_LINK_TAG  JAVASCRIPT_INCLUDE_TAG  TYPEERROR 

       

  RELATED


  2 COMMENTS


AGT [Reply]@ 2018-11-12 00:12:33

thank you so much, it fixed my problem. I owe you a coffee(1.8.0') now :))))

AGT [Reply]@ 2018-11-12 00:14:03

thank you so much, it fixed my problem. I owe you a coffee(1.8.0') now :))))



  RANDOM FUN

Lies of multiple cores