Stripe key not set in initializer - ruby-on-rails-4

I am having trouble setting the keys for stripe. I have set up an initializer:
Rails.configuration.stripe = {
:stripe_publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
:stripe_secret_key => ENV['STRIPE_SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:stripe_secret_key]
puts "================"
puts :stripe_secret_key
puts "================"
I added the puts to check the value in :stripe_secret_key and this is the output when I start up my local rails server:
$ STRIPE_PUBLISHABLE_KEY=pk_test_xxxxxx STRIPE_SECRET_KEY=sk_test_xxxxxx rails s
=> Booting WEBrick
=> Rails 4.0.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
================
stripe_secret_key
================
[2014-06-17 09:31:43] INFO WEBrick 1.3.1
[2014-06-17 09:31:43] INFO ruby 2.0.0 (2013-11-22) [x86_64-darwin13.0.0]
[2014-06-17 09:31:43] INFO WEBrick::HTTPServer#start: pid=51790 port=3000
Instead of the actual key what is being passed to the Stripe API is simply "stripe_secret_key". Any idea what the problem is? I'm sure it's simple, but I can't see it.

You are printing the symbol :stripe_secret_key with puts :stripe_secret_key, so the string stripe_secret_key gets printed.
Instead use puts Rails.configuration.stripe[:stripe_secret_key] Or puts Stripe.api_key to check the set stripe_secret_key value.

Related

Rake task in staging environment

I'm trying to rake a task in staging environment, so I've created a db.rake file in lib/tasks folder. For sure I'm missing something, but for some reason is not setting staging environment as it should. How do I know? Because I'm trying to print User.all to find every user but what I get is an empty array. In console I put rake db:clean_user_vitcords RAILS_ENV=staging
This is the task I've created at db.rake
namespace :db do
desc "TODO"
task clean_user_vitcords: :environment do
ap "entro aqui"
ap Rails.env
users = User.all
ap users.to_a
users.each do |user|
user.vitcords.reject! { |vitcord_id| Vitcord.find(vitcord_id).count == 0 }
user.save
end
end
end
And this is the output in console
"entro aqui"
"staging"
[]

Rails 4 I18n - missing translation after adding new locale file

Currently I have some locales subdirectories , which are correctly set in the configuration
config/application.rb
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
I have already 2 locales files , and I can get easily the translations :
config/locales/admin/dashboard.en.yml
en:
dashboard:
title: Dashboard
config/locales/admin/dashboard.fr.yml
fr:
dashboard:
title: Tableau de bord
irb(main):014:0> I18n.locale = :en
=> :en
irb(main):015:0> I18n.t("dashboard.title")
=> "Dashboard"
irb(main):016:0> I18n.locale = :fr
=> :fr
irb(main):017:0> I18n.t("dashboard.title")
=> "Tableau de bord"
Now I added 2 other locales files ( quite similar to previous ones...) into the SAME subdirectory 'locales/admin'
# =============
config/locales/admin/sheet.en.yml
en:
sheet:
title: Sheet
config/locales/admin/sheet.fr.yml
fr:
sheet:
title: Table
I RESTARTED the server ... and tried wo success to get the new added translations
irb(main):010:0> I18n.locale = :en
=> :en
irb(main):011:0> I18n.t("sheet.title")
=> "translation missing: en.sheet.title"
irb(main):012:0> I18n.locale = :fr
=> :fr
irb(main):013:0> I18n.t("sheet.title")
=> "translation missing: fr.sheet.title"
translations missing in BOTH languages? so I guess something is wrong in the subdirectories definition in the application.rb config file, as I checked the Rails.application.config.i18n.load_path ,a dn the newly added files ARE NOT in the path ..
"..../config/locales/admin/dashboard.en.yml",
"..../config/locales/admin/dashboard.fr.yml",
but not
"..../config/locales/admin/sheet.en.yml",
"..../config/locales/admin/sheet.fr.yml",
thanks for suggestions
It seems this issue has been already detected and it's related to the 'spring' process..
# https://github.com/rails/spring/issues/408
# rafaelfranca May 28
I think you got this error because you added the locale file after you
started the spring process for your environment, so when you add the
file it is not loaded inside the spring process. When you change the
application.rb the spring process is reloaded and your locale is now
working.
I changed one line ( added one blank line ...) in the application.rb than I restarted the server , and the new translations are found
rafael stated the rails console should restart the spring
Any rails command starts springs. rails console, rails generate,
rails server. You can stop the spring process with spring stop.
so, after ADDING a new locale file, better stopping spring before restarting the server
spring stop
rails server ( or rails console )
Change application.rb => Restart the Rails server
I would like to add that any time you make any change to application.rb you must restart the server for the change to take effect, not just the i18n component.

Rails 4.2 console issues - using RAILS_ENV=development

trying to run
$ rails c RAILS_ENV=development
1 warning and 1 error are raised which I do not understand
# warning :
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
# error
/config/initializers/devise.rb:13:in `+': no implicit conversion of nil into String (TypeError)
However , the config.eager_load is set to false in the development environment
config/environment/development.rb
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
…/…
And looking at the config/initializers/devise.rb ( line 13) I have
config/initializers/devise.rb
Devise.setup do |config|
…/…
(13) config.mailer_sender = 'no-reply#' + Rails.application.secrets.domain_name
…/…
which lead to the config/secrets.yml file
config/secrets.yml
development:
domain_name: example.com
it's quite understandable , as running rails c ( whithout RAILS_ENV) , I get
$ rails c
development environment (Rails 4.2.3)
irb: warn: can't alias context from irb_context.
irb(main):001:0> Rails.application.secrets.domain_name
=> "example.com"
this warning is also cryptic :
irb: warn: can't alias context from irb_context
could not find any info on Google search... but at least it runs in development ....
why this warning and error using RAILS_ENV ? any enlightenment welcome
too bad .. I should HAVE READ the latest 4.2 doc !!!
so I should NOT be using RAILS_ENV at all !!
$ rails console staging
Loading staging environment (Rails 4.2.3)
irb(main):001:0> exit
$ rails console development
Loading development environment (Rails 4.2.3)
irb: warn: can't alias context from irb_context.
irb(main):001:0> exit

Ruby on Rails 4 Whenever cron job working but not sure about output

I am newbie on Ruby on rails.
I have to implement auto-generate mail functionality with cronjobs using whenever gem and I have followed this link http://www.sitepoint.com/schedule-cron-jobs-whenever-gem/
What I have done---
1. Added user_notifier.rb file and set all mail actions as
class UserNotifier < ActionMailer::Base
default from: "myusername#example.com"
def two_hour_reminder
mail( :to => 'username#example.com' ,:subject => 'Reminder')
end
def mail_notification
UserNotifier.two_hour_reminder.deliver
end
end
2. Added schedule.rb
every 3.minutes do
rake 'send_digest_email'
end
3. Added scheduler.rake
desc 'send digest email'
task send_digest_email: :environment do
UserNotifier.mail_notification.deliver!
end
4. Added deploy.rb
require 'whenever/capistrano'
set :whenever_environment, defer { stage }
set :whenever_command, 'bundle exec whenever'
After this I have executed command grep CRON /var/log/syslog where i got following log
CMD (/bin/bash -l -c 'cd /home/username/repository && RAILS_ENV=production
bundle exec rake send_digest_email --silent')
But still I'm not getting any mail in inbox.
What I´m missing?
In schedule.rb, replaced rake 'send_digest_email' with command 'cd /home/username/repository && RAILS_ENV=development
bundle exec rake send_digest_email --silent'
:)

Configuring Blackfire on a base virtual box using Chef

I'm trying to give Blackfire.io (by Sensiolabs) a try to profile an existing PHP application running on a Vagrant machine (with PHP 5.3) on Mac.
I'm using Chef to provision my machine with Blackfire, but when running "vagrant provision" I get the following error:
default: STDERR: The server ID parameter is not set. Please run
blackfire-agent -register to configure it.
..which I already did
This is my Vagrant file:
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
Vagrant.configure("2") do |config|
..
config.vm.box = "covex/ubuntu1204-x64"
config.omnibus.chef_version = :latest
config.vm.provision "chef_solo" do |chef|
chef.json = {
:blackfire => {
:'server-id' => "d4860b49-be67-404b-9fa1-b..",
:'server-token' => "c412751f30d6c724033d8408e.."
}
}
chef.add_recipe "blackfire"
end
end
I followed the installation steps on https://blackfire.io/getting-started, except for the Probe paragraph.
Is my Vagrant file wrongly configured, so it can't read the server ID and token? Is the "brew install blackfire-php53" needed for this, if so, is there a way to configure this through my Vagrant file?
Guessing you are using https://supermarket.chef.io/cookbooks/blackfire
You missed the agent node in the config tree
{
"blackfire" => {
"agent" => {
"server-id" => "your server-id",
"server-token" => "your server-token",
}
}
}