Actionview::Template::Error with stripe when pushed to heroku - heroku

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.

Related

Why do the pictures attached to my seeded items not display on Heroku (ERROR 500)?

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.

How to deploy "quickstart-jekyll-zurb" to heroku

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.

Rails server won't start because of new relic error

When I try to start my Rails server, I am getting the following error:
I am using ruby 1.9.2
=> Booting WEBrick
=> Rails 3.1.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
/Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/newrelic_rpm-3.4.2/lib/new_relic/agent/agent.rb:318:in `log_app_names': undefined method `join' for nil:NilClass (NoMethodError)
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/newrelic_rpm-3.4.2/lib/new_relic/agent/agent.rb:439:in `start'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/newrelic_rpm-3.4.2/lib/new_relic/control/instance_methods.rb:95:in `start_agent'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/newrelic_rpm-3.4.2/lib/new_relic/control/instance_methods.rb:83:in `init_plugin'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/newrelic_rpm-3.4.2/lib/newrelic_rpm.rb:36:in `block in <class:Railtie>'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.8/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.8/lib/rails/initializable.rb:30:in `run'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.8/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.8/lib/rails/initializable.rb:54:in `each'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.8/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.8/lib/rails/application.rb:96:in `initialize!'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.1.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/toptier/Desktop/Proyectos/CursoIngles/config/environment.rb:5:in `<top (required)>'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:240:in `require'
from /Users/toptier/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.8/lib/active_support/dependencies.rb:240:in `block in require'
It is using the following gem: newrelic_rpm (3.4.2).
If I comment newrelic line in gemfile it works well,
Any idea?
I work at New Relic and we've tracked down the problem.
This happens when nil is explicitly set as the app name, which typically happens for local development of heroku apps that pull their app name from ENV["NEW_RELIC_APP_NAME"]. Since this environment variable is not typically set on your local dev box it comes into the agent's config as nil and crashes the local server. It doesn't effect deployed versions of the app where this variable is set.
Obviously the agent should handle this case gracefully, and we'll have a patch out in the next day or two. We just completed a major refactoring of the agent's configuration, and this edge case was missed in our internal testing.
etoleb gives a good workaround in the comment. We're very sorry for causing you this headache.
If you have any questions or concerns feel free to email me directly at sam#newrelic.com.
Thanks!
The issue seems to be related to the app_name setting being blank in your newrelic config. Personally I went through the Heroku installation (so your config may look different) but this is what I did:
Within config/newrelic.yml (copied from https://gist.github.com/2253296) I removed the line
app_name: <%= ENV["NEW_RELIC_APP_NAME"] %>
from the common config (line 35 for me) into the production config (after line 247 for me), which winds up looking like
production:
<<: *default_settings
monitor_mode: true
app_name: <%= ENV["NEW_RELIC_APP_NAME"] %>
Great to see a reply from someone who can take responsibility! Nice work, New Relic. Thanks, #samg.
Since the issue is just a nil env value, rather than downgrading the gem or diddling with config files, I just added the environment variable.
It's easy to see what the setting is on heroku:
$ heroku config
...
NEW_RELIC_APP_NAME: my_app_name
NEW_RELIC_ID: 123456
NEW_RELIC_LICENSE_KEY: 982987ae987987af98798something7e897987987c7b9d7
NEW_RELIC_LOG: stdout
...
I then opted to set a local env var via my project's .rvmrc file, where I so some other similar things:
rvm use ruby-1.9.2-p290#ConTracker --create
export PATH=bin:$PATH
export NEW_RELIC_APP_NAME=my_app_name
Then it just took a cd .. and a cd back in to my project, and it was working with the gem on version 3.4.2.
Party on!
Thanks for the comment. The answer is to downgrade to 3.4.1.

Heroku / Ruby-on-Rails error: image not precompiling

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.

deploying Rails 3.1 namespaced assets to Heroku

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.

Resources