Why can't Rails find '../javascripts/application.js'? - heroku

I just updated my Rails application to 5.0.0.rc1 and it is now not able to load my assets. The initial error claimed that I need a manifest.rb file in assets/config. I did not have this folder so I created it along with the manifest.rb file. Here is my manifest.rb file:
//= link ../javascripts/application.js
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link_directory ../stylesheets .sass
//= link_tree ../javascripts .js
//= link_tree ../images
And now I am getting this:
ActionView::Template::Error (couldn't find file '../javascripts/application.js' under '/Users/Clover/Desktop/Code/myroomies/app/assets/config'):
4: RoomiesApp
5: <%= csrf_meta_tags %>
6: <%= stylesheet_link_tag 'application.css.sass', media: 'all', 'data-turbolinks-track' => 'reload' %>
7: <%= javascript_include_tag 'application', 'data-turbolinks-track' => 'reload' %>
8:
9:
10:
app/assets/config/manifest.js:1
app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___1555946743671048113_70305755306180'
Rendering /Users/Clover/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout
Rendering /Users/Clover/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered /Users/Clover/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (3.8ms)
Rendering /Users/Clover/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered /Users/Clover/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.6ms)
Rendering /Users/Clover/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered /Users/Clover/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.6ms)
Rendered /Users/Clover/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (60.2ms)
My application.js file is definitely at that route as far as I can tell.
My application is currently running in Heroku with no problems. So I cloned the repo directly from Heroku. It didn't have the assets/config folder, but still seems to be working fine. I understand there is a difference between production and development environments, but I am not still not clear on how to toggle properly between the two. What am I missing here?

Related

The asset "application.js" is not present in the asset pipeline in Rails 6

I am creating a RoR-6 app and I get the following error thrown from application.html.erb file from this line:
javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
I get the following error:
ActionView::Template::Error: The asset "application.js" is not present in the asset pipeline.
The app was created by running rails new myapp -d postgres
I am using rails 6.0.0.rc1
You'll want to use javascript_pack_tag instead of javascript_include_tag:
javascript_pack_tag 'application', 'data-turbolinks-track': 'reload'
This is required because webpacker handles javascript compilation in Rails 6.
If you do not want to use Webpack, add the following to config/initializers/assets.rb:
Rails.application.config.assets.precompile += %w(application.js)
Place this line in the application.html.erb:
<%= javascript_pack_tag 'application' %>
This worked on my end.
Running yarn build solved the issue for me (which in the first place was caused by running rails assets:clobber)

Render SASS files correctly in File.read (inside PDF file)

I generate a pdf and have to include css in the generated file so that the styling is correct in the pdf. To do this I have
<%= File.read(Rails.root.join("app", "assets", "stylesheets", "application.css.scss")) %>
<%= File.read(Rails.root.join("app", "assets", "stylesheets", "app.css.scss")) %>
But the sass isn't templated correctly. Does anyone know what the correct code to render the files right are?
replace File.read with
YourApp::Application.assets["application.css.scss"].to_s.html_safe
where YourApp is the name of the application you are working on. This will cause rails to render the scss inline.

Heroku Rails 3.2 ActionView::Template::Error ( ...(file)... has a invalid UTF-8 byte sequence):

Hey I'm getting this error in my Rails app (Heroku, production, Rails 3.2.3):
ActionView::Template::Error (/app/vendor/assets/javascripts/star-rating/jquery.MetaData.js has a invalid UTF-8 byte sequence):
3: <head>
4: <title>ContactTool</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__630446545548622900_53107960'
It started to happen after changing to lazy loading in production, which I need:
application.rb
...
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
# Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
Bundler.require(:default, :assets, Rails.env)
end
...
How do I fix this? Thanks!
Update:
I removed the file just to test whether or not the error was only related to that file, and it was. Without this file everything works fine. I will need this file though, so if anybody knows why I'd get an error on the utf8
Put # encoding: utf-8 on the first line in your view (note the #)
There was a change in rails 3 (if i'm not mistaken) that does something with utf-8 encoding

Jruby, Rails3.1, Sprockets - Same File error

On windows, running Jruby 1.6.4 - this issue occurs in Sprockets 2.0.0 and 2.0.2, Rails 3.1.0 and 3.1.1. Using therubyrhino as the js runtime, but this also occurs when using execjs (which correctly finds jscript).
Spin up a sample Rails project with a scaffolded controller. Start the server. Edit the controller's css.scss file with any change & save. Refresh the page. On Mac/Linux - things are fine. However, on windows you receive a "same file" error. This happens every time you change the css.scss file - and you must run: rake assets:clean to get past it.
Same behavior for coffeescript files (though again, only on windows). Asked the sprockets guys, but they recommended I ask the Rails core team (which I have). Decided to fork the questioning here as well.
Any thoughts?
BTW, here's a sample of the error:
ActionView::Template::Error (same file: C:/DEV/Information_Center/rubyw/edist3/tmp/cache/assets/sprockets%2F25f4cb117025b2fbc2fb480688c87da0.6816.15608 and C:/DEV/Information_Center/rubyw/edist3/tmp/cache/assets/D34/450/sprockets%2F25f4cb117025b2fbc2fb480688c87da0):
3:
4: <%= yield :page_title %> | foo.com
5: <%= stylesheet_link_tag "application" %>
6: <%= stylesheet_link_tag "article" %>
7: <%= javascript_include_tag "application" %>
8: <%= javascript_include_tag "article" %>
9: <%= csrf_meta_tags %>
app/views/layouts/article.html.erb:6:in `_app_views_layouts_article_html_erb___1475428847_7158'
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack- 3.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.0ms)
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack- 3.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.0ms)
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack- 3.1.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (0.0ms)
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.0ms)
Rendered C:/DEV/programs/jruby-1.6.4/lib/ruby/gems/1.8/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (0.0ms)
Workaround
Well - not much traction from the Rails core team just yet on this, but this workaround seems to allow sprockets and Rails to play a little nicer, via Jruby on Windows:
-add to development.rb
config.assets.cache_store = nil

Can't get asset pipeline working

I can't get the asset pipeline working for some reason. I get a 404 on request to both application.css and application.js. I'm using rails 3.1.0.rc6. Nothing special, just created a new project.
In my layout file:
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
It's linking to /stylesheets/application.css and same with the js file. I'm using pow but also tried starting the server with webrick.
Any ideas?
Note: using sprockets 2.0.0.beta.15
Figured it out. I had to make an explicit require call to "sprockets/railtie"
You might find that adding
config.serve_static_assets = true
to your config/environments/xxx.rb will help.
To be more exact, add this to your Gemfile
gem 'sprockets/railtie'

Resources