I know that Heroku is running the rake assets:precompile task:
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
-----> Rails plugin injection
Injecting rails_log_stdout
Injecting rails3_serve_static_assets
-----> Discovering process types
Procfile declares types -> (none)
Default types for Ruby/Rails -> console, rake, web, worker
-----> Compiled slug size is 17.7MB
-----> Launching... done
And I told it to precompile images in production.rb
# from: http://stackoverflow.com/questions/8052865/rails-3-1-asset-pipeline-why-my-images-do-not-precompile-for-production
config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif]
So why do I still get this 500 error?
2012-05-29T02:57:15+00:00 app[web.1]: Started GET "/signin" for 46.114.68.16 at 2012-05-29 02:57:15 +0000
2012-05-29T02:57:15+00:00 app[web.1]: Processing by SessionsController#new as HTML
2012-05-29T02:57:15+00:00 app[web.1]: Rendered sessions/new.html.erb within layouts/application (25.4ms)
2012-05-29T02:57:15+00:00 app[web.1]: Completed 500 Internal Server Error in 27ms
2012-05-29T02:57:15+00:00 app[web.1]:
2012-05-29T02:57:15+00:00 app[web.1]: ActionView::Template::Error (twitter_64.png isn't precompiled):
2012-05-29T02:57:15+00:00 app[web.1]: 25: <div id="auths">
2012-05-29T02:57:15+00:00 app[web.1]: 27: <a href="/auth/twitter" class="provider">
2012-05-29T02:57:15+00:00 app[web.1]: 26: <h2>Or sign in through one of these:</h2>
2012-05-29T02:57:15+00:00 app[web.1]: 28: <%= image_tag "twitter_64.png", :size => "64x64", :alt => "Twitter" %>Twitter</a>
Interestingly, I have images on other pages that show just fine. Don't know why some images wouldn't work, but some would...
First, be sure you have this set as well:
config.assets.initialize_on_precompile = false
If that doesn't work, it's worth trying to manually run the precompile task before building the slug; I think there are subtle differences when done this way:
RAILS_ENV=production bundle exec rake assets:precompile
Last, it's not a solution, but if all else fails, a temporary workaround would be to set
config.assets.compile = true
Make sure you are putting your images in
app/assets/images
and not in
public/assets
directly.
Then run rake assets:precompile and see if it improves. It can get a bit confusing.
Related
I am using rails 5.1.7 with the gem react-rails.
I added a react component in a erb view as:
<%= react_component("cardlist", { all_cards: #all_cards }, {prerender: true}) %>
Which works fine on my local environment, but when deploying the app to heroku, if I try to access the erb containing the react_component helper I get the following message in the logs:
ActionView::Template::Error (No such file or directory # rb_sysopen - /app/public/packs/js/server_rendering-7bdf65f03078e0e44c86.js
I have tried adding an App component as well and rendering that instead, but it keeps giving the same messages.
I have also added a node buildpack on heroku and I ensured the app only uses npm instead of yarn, with the node version added:
"engines": {
"node": "12.18.3"
}
But I always get the same message
ActionView::Template::Error (No such file or directory # rb_sysopen - /app/public/packs/js/server_rendering-7bdf65f03078e0e44c86.js
If I set pre render to true the component appears in production with no errors on the log, but I need it done with server rendering.
After deleting the files in public/packs and compiling in the production environment as Justing suggested I am getting:
2020-09-30T05:35:06.341918+00:00 app[web.1]: F, [2020-09-30T05:35:06.341829 #4] FATAL -- : [ce9e5a3a-b642-4de0-bb80-e4210172c687] ActionView::Template::Error (Webpacker can't find server_rendering.js in /app/public/packs/manifest.json. Possible causes:
2020-09-30T05:35:06.341919+00:00 app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2020-09-30T05:35:06.341919+00:00 app[web.1]: unless you are using the `webpack -w` or the webpack-dev-server.
2020-09-30T05:35:06.341920+00:00 app[web.1]: 2. webpack has not yet re-run to reflect updates.
2020-09-30T05:35:06.341921+00:00 app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2020-09-30T05:35:06.341921+00:00 app[web.1]: 4. Your webpack configuration is not creating a manifest.
2020-09-30T05:35:06.341922+00:00 app[web.1]: Your manifest contains:
2020-09-30T05:35:06.341922+00:00 app[web.1]: {
2020-09-30T05:35:06.341923+00:00 app[web.1]: }
2020-09-30T05:35:06.341923+00:00 app[web.1]: ):
2020-09-30T05:35:06.342250+00:00 app[web.1]: F, [2020-09-30T05:35:06.342174 #4] FATAL -- : [ce9e5a3a-b642-4de0-bb80-e4210172c687] 44: <% #hotel_search_filter = t :hotel_search__filter %>
2020-09-30T05:35:06.342252+00:00 app[web.1]: [ce9e5a3a-b642-4de0-bb80-e4210172c687] 46: <%= #count_filters = count_filters %>
2020-09-30T05:35:06.342255+00:00 app[web.1]: [ce9e5a3a-b642-4de0-bb80-e4210172c687] 47: <%= react_component("App", { all_ro
My webpack config file:
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
- .eot
- .otf
- .ttf
- .woff
- .woff2
extensions:
- .jsx
- .mjs
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
pretty: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: true
# Extract and emit a css file
extract_css: true
# Cache manifest.json for performance
cache_manifest: true
works fine on my local environment
Did you try precompiling locally?
RAILS_ENV=production NODE_ENV=production rake assets:precompile
Then run your rails app with
RAILS_ENV=production rails s
The error should be pretty obvious. My guess is that you have some error during the precompile so the file js/server_rendering-7bdf65f03078e0e44c86.js doesn't exist.
You might also want to ensure that you don't have any files in your /public/packs directory checked into your git repo.
First-time poster, I tried to follow the rules but please tell me if anything is missing and/or needs to be edited in this question.
TL;DR : using ActiveStorage, pictures associated to items display fine on localhost but not on Heroku
Initial setup
In an educational context, my team and I are building a simple Ruby On Rails application. We have to use Ruby 2.5.1 and Rails 5.2.4 with a postgresql 9.5 database in development, and we have to use Heroku for production.
The source code is hosted on a GitLab instance name Framagit. We are using the GitLab pipeline to deploy the code to Heroku everytime a merge is completed in the staging branch.
Procfile is as follows :
realease: rails db:migrate && rails db:seed
web: rails server
On this app, the main model is Compost. Each instance has one picture. These pictures are stored under :
app/assets/images/compost_pictures/compost_{001-007}.jpg
ActiveStorage setup
ActiveStorage has been installed by running $ rails active_storage:install followed by $ rails db:migrate which created the active_storage_attachments and active_storage_blobs tables in db/schema.rb.
app/models/compost.rb was updated with :
# Active Storage picture association
has_one_attached :picture
app/views/composts/show.html.erb now includes :
<div class="col-8">
<% if #compost.picture.attached? %>
<%= image_tag #compost.picture, style:"height: auto; max-width:100%" %>
<% else %>
<h3> Hey, why don't you provide a nice compost picture ?</h3>
<% end %>
</div>
(also tried with image_tag url_for(#compost.picture) with no success on Heroku, although it works on localhost)
(#compost is set in the controller and works fine for other composts attributes display)
and db/seeds.rb was updated with :
def compost_seed(user)
new_compost = user.owned_composts.create!( all the attributes...)
picture_file_name = 'compost_' + (format '%03d', rand(1..7)) + '.jpg'
picture_path = Rails.root.join("app", "assets", "images", "compost_pictures", picture_file_name)
new_compost.picture.attach(
io: File.open(picture_path),
filename: picture_file_name,
content_type: "image/jpg"
)
end
Running the server
Locally
On localhost with the Rails server set to development, everything works fine, pictures are displayed.
I've set up a simulated production environment like this :
$ RAILS_ENV=production rails db:create db:migrate
# completed with no error
$ RAILS_ENV=production rails assets:precompile
# completed with no error
$ RAILS_ENV=production rails db:seed
# completed with no error
$ RAILS_ENV=production SERVE_STATIC_ASSETS=true rails server
# server runs smoothly
Everything works fine, pictures are displayed.
On Heroku
none of the pictures is displayed : they are replaced by a broken image symbol
when in Heroku rails console, > Compost.all.sample.picture.attached? returns true
in the browser, the URL of the image is https://ok-compost-staging.herokuapp.com/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSWRaV2huZW1SRGVESkRTRE5sWWxoSGJYSlJSakpTVG5OVUJqb0dSVlE2RUdScGMzQnZjMmwwYVc5dVNTSkphVzVzYVc1bE95Qm1hV3hsYm1GdFpUMGlZMjl0Y0c5emRGOHdNRFl1YW5Cbklqc2dabWxzWlc1aGJXVXFQVlZVUmkwNEp5ZGpiMjF3YjNOMFh6QXdOaTVxY0djR093WlVPaEZqYjI1MFpXNTBYM1I1Y0dWSklnOXBiV0ZuWlM5cWNHVm5CanNHVkE9PSIsImV4cCI6IjIwMTktMTItMDdUMDA6NDM6NTUuNTYzWiIsInB1ciI6ImJsb2Jfa2V5In19--ee616a99d031d361f2b63aeb869ca5d787ef44a8/compost_006.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%22compost_006.jpg%22%3B+filename%2A%3DUTF-8%27%27compost_006.jpg and trying to visit it ends up with a 'We're sorry, but something went wrong'.
The logs are :
2019-12-07T00:44:44.433822+00:00 heroku[router]: at=info method=GET path="/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSWRVMVI1ZERoQ1ZXUlFibUpTTVZGNFRWbEVUamhaVldsMkJqb0dSVlE2RUdScGMzQnZjMmwwYVc5dVNTSkphVzVzYVc1bE95Qm1hV3hsYm1GdFpUMGlZMjl0Y0c5emRGOHdNREV1YW5Cbklqc2dabWxzWlc1aGJXVXFQVlZVUmkwNEp5ZGpiMjF3YjNOMFh6QXdNUzVxY0djR093WlVPaEZqYjI1MFpXNTBYM1I1Y0dWSklnOXBiV0ZuWlM5cWNHVm5CanNHVkE9PSIsImV4cCI6IjIwMTktMTItMDdUMDA6NDk6MzcuMzI2WiIsInB1ciI6ImJsb2Jfa2V5In19--cae4ff5349cfa4a394c081da5827f0c35ce96c08/compost_001.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%22compost_001.jpg%22%3B+filename%2A%3DUTF-8%27%27compost_001.jpg" host=ok-compost-staging.herokuapp.com request_id=e8ca9a03-07c4-459d-ab20-4e096da30e87 fwd="78.201.127.110" dyno=web.1 connect=0ms service=4ms status=500 bytes=1827 protocol=https
2019-12-07T00:44:47.277080+00:00 app[web.1]: I, [2019-12-07T00:44:47.276974 #4] INFO -- : [f8400596-5b61-4569-ad22-b514afe4b32a] Started GET "/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSWRVMVI1ZERoQ1ZXUlFibUpTTVZGNFRWbEVUamhaVldsMkJqb0dSVlE2RUdScGMzQnZjMmwwYVc5dVNTSkphVzVzYVc1bE95Qm1hV3hsYm1GdFpUMGlZMjl0Y0c5emRGOHdNREV1YW5Cbklqc2dabWxzWlc1aGJXVXFQVlZVUmkwNEp5ZGpiMjF3YjNOMFh6QXdNUzVxY0djR093WlVPaEZqYjI1MFpXNTBYM1I1Y0dWSklnOXBiV0ZuWlM5cWNHVm5CanNHVkE9PSIsImV4cCI6IjIwMTktMTItMDdUMDA6NDk6MzcuMzI2WiIsInB1ciI6ImJsb2Jfa2V5In19--cae4ff5349cfa4a394c081da5827f0c35ce96c08/compost_001.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%22compost_001.jpg%22%3B+filename%2A%3DUTF-8%27%27compost_001.jpg" for 78.201.127.110 at 2019-12-07 00:44:47 +0000
2019-12-07T00:44:47.277980+00:00 app[web.1]: I, [2019-12-07T00:44:47.277897 #4] INFO -- : [f8400596-5b61-4569-ad22-b514afe4b32a] Processing by ActiveStorage::DiskController#show as JPEG
2019-12-07T00:44:47.278103+00:00 app[web.1]: I, [2019-12-07T00:44:47.278010 #4] INFO -- : [f8400596-5b61-4569-ad22-b514afe4b32a] Parameters: {"content_type"=>"image/jpeg", "disposition"=>"inline; filename=\"compost_001.jpg\"; filename*=UTF-8''compost_001.jpg", "encoded_key"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDRG9JYTJWNVNTSWRVMVI1ZERoQ1ZXUlFibUpTTVZGNFRWbEVUamhaVldsMkJqb0dSVlE2RUdScGMzQnZjMmwwYVc5dVNTSkphVzVzYVc1bE95Qm1hV3hsYm1GdFpUMGlZMjl0Y0c5emRGOHdNREV1YW5Cbklqc2dabWxzWlc1aGJXVXFQVlZVUmkwNEp5ZGpiMjF3YjNOMFh6QXdNUzVxY0djR093WlVPaEZqYjI1MFpXNTBYM1I1Y0dWSklnOXBiV0ZuWlM5cWNHVm5CanNHVkE9PSIsImV4cCI6IjIwMTktMTItMDdUMDA6NDk6MzcuMzI2WiIsInB1ciI6ImJsb2Jfa2V5In19--cae4ff5349cfa4a394c081da5827f0c35ce96c08", "filename"=>"compost_001"}
2019-12-07T00:44:47.279105+00:00 app[web.1]: I, [2019-12-07T00:44:47.279040 #4] INFO -- : [f8400596-5b61-4569-ad22-b514afe4b32a] Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)
2019-12-07T00:44:47.279772+00:00 app[web.1]: F, [2019-12-07T00:44:47.279702 #4] FATAL -- : [f8400596-5b61-4569-ad22-b514afe4b32a]
2019-12-07T00:44:47.279842+00:00 app[web.1]: F, [2019-12-07T00:44:47.279773 #4] FATAL -- : [f8400596-5b61-4569-ad22-b514afe4b32a] Errno::ENOENT (No such file or directory # rb_file_s_mtime - /app/storage/ST/yt/STyt8BUdPnbR1QxMYDN8YUiv)
The images were properly displayed when we fetched them via their URL in the assets pipeline.
So, what now ?
According to the logs, we guess this is a path issue. What are we missing ? At what point are we mistaken ?
We'll update the post with any required code snippet or test result, this is an educational project and nothing about it is private or sensitive.
Any insight or pointer appreciated :)
Workaround : use cloud storage instead of local disk in production
Since all the other images (background, logos, etc.) were displayed properly, the problem had to lie with our Active Storage use.
According to Heroku doc on Active Storage they use Ephemeral Disks for Active Storage and files are not persisted neither across dyno nor over time. So our guess was that our attachments were not stored on the dyno that served our application.
Connecting the production storage to a free-tier AWS bucket as suggested in Heroku doc worked for us and images are displayed properly.
I've cloned this repo:
https://github.com/lvillani/quickstart-jekyll-zurb
I got it working locally no problem.
I added a Procfile with the following:
web: bundle exec jekyll serve -P $PORT
Heroku accepts the bundle no problem.
But the server crashes when trying to load a page.
The first problem I had was that it was trying to render a misformated vendor page.
I fixed that by adding this to _config.yml:
exclude:
- "vendor/bundle/ruby
But now my app.scss file can't #import "foundation/settings";.
Here is the relevant portion of the Heroku logs.
"2014-10-16T19:56:05.366451+00:00 app[web.1]: Generating...
2014-10-16T19:56:05.361060+00:00 app[web.1]: Configuration file: /app/_config.yml
2014-10-16T19:56:06.277480+00:00 app[web.1]: Conversion error: There was an error converting 'asset/app.scss'.
2014-10-16T19:56:06.277526+00:00 app[web.1]: jekyll 2.1.1 | Error: File to import not found or unreadable: foundation/settings.
2014-10-16T19:56:06.277529+00:00 app[web.1]: Load path: /app/_vendor/foundation/scss
Everything works fine locally, so I assume this is a Heroku configuration issue but I don't know enough about Heroku to begin to know where to look.
thanks!
Maybe you forgot to run a make setup.
Note that your jekyll is 2.1.1 and current version is 2.4.
Folks,
I'm attempting to deploy a rails webapp on Heroku using Stripe. This might be a precompiling asset problem. I checked the heroku error logs and there is an actionview template error "undefined method stripe"
Everything works fine on my local machine, it's just something going wrong when pushing to heroku.
2013-02-11T00:22:53+00:00 app[web.1]: ActionView::Template::Error (undefined method `stripe' for #<Rails::Application::Configuration:0x00000003397440>):
2013-02-11T00:22:53+00:00 app[web.1]: 7:
2013-02-11T00:22:53+00:00 app[web.1]: 6: </article>
2013-02-11T00:22:53+00:00 app[web.1]: 9: data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
2013-02-11T00:22:53+00:00 app[web.1]: 8: <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
2013-02-11T00:22:53+00:00 app[web.1]: 10: data-description="You'll get your information in 2 days!"
Hope someone has some insight in to this issue. I tried just downloading the full stripe.js file and putting it in my assets folder, but that didn't seem to help.
This doesn't appear to be related to asset compilation or stripe.js. This is the line that is failing in your view:
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
Heroku runs your app with your production environment settings. Is it possible you only have Rails.configuration.stripe set in development.rb, or somewhere similar?
I had the same issue, but it was because when I first started testing Stripe on development I had the actual keys in my stripe.rb file, so I added it to my .gitignore to keep from versioning those keys. When updated my code to run in production, I used ENV vars instead but forgot to remove the that stripe.rb from the .gitignore. Double check to make sure you reconfigure your variables, stop ignore the file, and you should be set.
I have a Rails 3.1 application running on Heroku Cedar and it has a custom built Admin panel.
Admin is just a namespaced controller/view combination which live in controllers/admin and in views/admin.
I also 'namespaced' the assets: called them assets/javascripts/admin.js.coffe and assets/stylesheets/admin.css.scss and include both from layouts/admin/application.html.haml
Heroku perfectly compiles application.(css.scss|js.coffee) to a javascript/stylesheet files. When I visit frontend application it just works.
But when I visit '/admin' I get the following error:
When I visit website in production I get the following error:
2011-09-19T15:47:18+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/execjs-1.2.5/lib/execjs/runtimes.rb:46:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
2011-09-19T15:47:18+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/execjs-1.2.5/lib/execjs.rb:5:in `<module:ExecJS>'
2011-09-19T15:47:18+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/execjs-1.2.5/lib/execjs.rb:4:in `<top (required)>'
2011-09-19T15:47:18+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
2011-09-19T15:47:18+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'
2011-09-19T15:47:18+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency'
2011-09-19T15:47:18+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
2011-09-19T15:47:18+00:00 heroku[web.1]: Process exited
2011-09-19T15:47:20+00:00 heroku[web.1]: State changed from starting to crashed
According to Heroku's documentation I don't need to add gems like therubyracer-heroku to my gemfile. My admin asset files are manifest files and are similar to application asset manifests:
# application.js.coffee
#= require jquery
#= require jquery_ujs
# admin.js.coffee
#= require jquery
#= require jquery_ujs
Any thoughts?
Update 19 sept: As it turns out, admin assets are never compiled into public/assets and neither are present in public/assets/manifest.yml
Did you update your application's PATH, as also mentioned in the Heroku documentation you linked?
I had this same problem, adding 'bin' to the PATH solved it.