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'
Related
this is my first time asking a question here, I hope I would explain my problem well.
In one of my recent tasks, I'm upgrading our app to Ruby and Rails (Ruby 2.6.6 > 2.7.2, Rails 6.0.3.2. > 6.1.1)
I had several issues along the way, upgraded some gems and JS libraries. The application runs fine in development mode. However when I switch to production mode, I run these commands to compile and run the server.
RAILS_ENV=production bundle exec rake webpacker:compile
./node_modules/webpack/bin/webpack.js --config webpack.config.js
When I run the app, in production mode it looks running normal, but when I go to localhost:3000 it throws several 500 errors regarding to CSS files. I see the main page of the app as plain HTML, without CSS.
2021-01-22 11:50:51 -0500 Rack app ("GET /assets/stylesheets/app-styles-3661efb317da3fb28f52.css" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
2021-01-22 11:50:25 -0500 Rack app ("GET /assets/landing.debug-05588bd014e46c264aaf6e00d2f5c570dd7ca3ed42336c2ff6d5c05bf986afe2.js" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
2021-01-22 11:50:25 -0500 Rack app ("GET /assets/companyLogo-6700adf796812269b9428251803c253b9c073095ef511d3619d269a0fdd96435.png" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
Files which are mentioned in the error are exists under the /public folder. In the browser's page source, I can see the path as well. When I click the folder path on page source, I see this error on the browser.
An unhandled lowlevel error occurred. The application logs may have details.
When I check the docs of RoR, the match? method for ActionDispatch::FileHandler is not there, but in 6.0.3.2 docs, it is deprecated without a notice, maybe.?. It is not something I call intentionally, it is probably called somewhere in Rails when the app is running on production mode.
I have those helper in my erb files.
<%= javascript_pack_tag 'application' %>
<%= stylesheet_pack_tag 'application' %>
I tried replacing them with
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
but no luck :(
I tried this as well.
Is anyone have an idea how can I make sure Rails is loading these files and accessible in the user side? Or any better debugging suggestions are appreciated!
Thanks in advance!
Note: When I switch to development mode, everything works fine.
BTW, Some Packages I use:
"#rails/webpacker": "5.2.1" #-> was 4.0.2
"webpack-bundle-analyzer": "3.3.2"
"webpack-manifest-plugin": "3.0.0-rc.0" #-> was 2.0.4
"webpack-cli": "4.4.0", #-> was 3.3.0 and it was only devDependency
We had the same issue with the match? method missing for ActionDispatch::FileHandler
We traced it back to: https://github.com/romanbsd/heroku-deflater/issues/54
Removing the heroku-deflater gem fixed it for us
If you have issues with this and get a error like this:
ActionView::Template::Error (Webpacker can't find application.css in /webapp/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
"application.js": "/packs/js/application-26b24ac7b08f8a1b640f.js",
"application.js.map": "/packs/js/application-26b24ac7b08f8a1b640f.js.map",
"entrypoints": {
"application": {
"js": [
"/packs/js/application-26b24ac7b08f8a1b640f.js"
],
"js.map": [
"/packs/js/application-26b24ac7b08f8a1b640f.js.map"
]
},
}
):
You can resolve it by deleting the stylesheet_pack_tag in app/views/layouts/application.html.erb. The javascript_pack_tag directive loads the scss/css.
You can see in the error message entrypoints that the scss was not generated, its inside the js. I've self inflicted this error on me because of outdated guides.
Example
With the following files & contents:
app/javascript/packs/application.js
// rails generated stuff
import "styles/application.scss"
app/javascript/styles/application.scss
// some scss rules
body { background-color: red; }
app/views/layouts/application.html.erb:
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
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)
Running Rails 4 and deployed to Heroku and have been struggling with a strange issue.
Config contains:
config.assets.compile = true
Gemfile contains:
gem 'rails_12factor', group: :production
Have a line in my application.html.erb to render an image:
<%= image_path('image.jpg') %>
Placed my image in the following locations (excessive but troubleshooting):
assets
assets/images
public
public/images
I am compiling assets during my deployment to Heroku (slug compilation) and no errors are returned.
When I open the webpage the image is not rendered and instead the path is provided as:
"/images/image.jpg"
Any thoughts as to why this is occurring?
Thank you all in advanced
That is the expected behaviour for image_path. I think what you're looking for is image_tag.
For example, if your image is assets/images/image.png to render it in the view you would use:
<%= image_tag('image.png') %>
That is the recommended method, but you could also do
<img src="<%= image_path('image.png')%>" />
I am struggling BIG TIME with getting this framework set up correctly. Has anyone successfully been able to get this working? If so, I would love any and all feedback. Thanks!
I'm following the instructions from http://compass-style.org/install/ and wondering where to put the files within the Rails 3.1 app: inside app/assets/stylesheets or keep it in app/stylesheets as it resides when installing compass?
Also, compass gives a set of instructions after $ compass init rails . --using blueprint below:
Now add these lines to the head of your layout(s):
%head
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= stylesheet_link_tag 'print.css', :media => 'print'
/[if lt IE 8]
= stylesheet_link_tag 'ie.css', :media => 'screen, projection'
This looks like HAML (which I'm not familiar with). I add these link tags using .erb instead and nothing seems to work.
Putting this into my config/application.rb worked for me:
config.sass.load_paths ||= []
config.sass.load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
config.sass.load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/blueprint/stylesheets"
REF: https://github.com/rails/sass-rails/issues/3
I am newbe here about Netzke..
I am trying to follow the installation process in the Netzke web
site http://www.netzke.org and also from the git Netzke-core site..
I just download the EXT JS 4.0.2 zip file from Sencha, extract it and try to symbolic link the ext JS code to <railsdir>public/extjs directory..
and with the rails 3.1, I try also to link it to <railsdir>/app/assets/
javascripts and also <railsdir>/app/assets/stylesheets..
But it still does not work, because it doesn't find the file /extjs/resources/css/ext-all.css..
Please can you help which path or directory to link the EXT JS code to?
Linking the /code/sencha/EXT-4.0.2a to public/extjs
, that what I have done, but no success..
set config.assets.debug = false in environment/development.rb file
it will work with Netzke
I'm just newbie for Netzke too. I think your problem with model_name method is that you Use GridPanel without a config model to it. You should do something like this:
<% netzke :some_component, :class_name => "Netzke::Basepack::GridPanel", :model => "YourModel" %>
It should work :)