Rails 4 I18n - missing translation after adding new locale file - ruby-on-rails-4

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.

Related

Require rest-client to module in Chef

I need to include res-client into my module in order to use RestClient::Resource.
I use the method in the module in a Chef recipe (ruby_block resource).
When my ruby_block resource tries to run the method in the module it output this error:
ERROR: cannot load such file -- rest-client
The following is my module residing in libraries folder:
module SecretServer
def fetch_token
payload = { :username => "***", :password => "***", :grant_type => "****"}
uri = ***
request = RestClient::Resource.new(uri, :verify_ssl => false)
post_request = request.post payload, :content_type => 'application/x-www-form-urlencoded'
token = JSON.parse(post_request)["access_token"]
return token
end
end
require 'rest-client'
Chef::Recipe.include(SecretServer)
Chef::Resource.include(SecretServer)
The following is the resource that calls the function in module:
ruby_block 'parse data' do
block do
res = fetch_token
puts res
end
end
This is just one of the several recipes in my cookbook. This recipe runs after the target node is almost ready and 'bundle install' has been run on the target node.
I also install rest-client in the target node. I tried each of following resource before my ruby_block resource:
chef_gem 'rest-client' do
action :install
end
gem_package 'rest-client' do
action :install
end
My question is how to include 'rest-client' and utilize it in Chef recipes?
Long ago, the HTTP clients lived together in harmony. Then everything changed when the JSON gem attacked. Only the Chef::HTTP was still to be included with Chef as all the other clients were under too much flux to include.
We don't include that gem anymore, so to use it, you would have to install it yourself either via a cookbook gem dependency or a chef_gem resource. But for simple stuff you can just use our Chef::HTTP::SimpleJSON client instead:
Chef::HTTP::SimpleJson.new(uri).post("", args)["access_token"]
Or something like that (specifics depend on if you must use form encoding or if the server also speaks JSON).

Error (upload image) after deploy using capistrano rails 4

Yesterday i tried to deploy my rails app to my own server. For deploy, i have followed gorails tutorial -> https://gorails.com/deploy/ubuntu/14.04. After deployed, finally my rails app has running live. But i have a problem when i try to create room module with image, i get error like this
We're sorry, but something went wrong.
If i create room without image, it success. I'm sure that i can't upload image.
gem 'paperclip'
room.rb
has_attached_file :image, :styles => { :for_index => "336x227>", :thumb => "150x150>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
deploy.rb
lock '3.1.0'
set :application, 'hotelxxxxx'
set :repo_url, 'git#bitbucket.org:xxxxxx/hotelxxxxx.git'
set :deploy_to, '/home/xxxxxx/hotelxxxxx'
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
How to fix that?
The first step to troubleshoot this issue would be to look at the Rails log on your server. It should be in the log/production.log file. Having the actual error message in the log would make it a lot easier to help you figure this out.
Finally image uploaded !! I see error from nginx error.log => 'Paperclip::Errors::NotIdentifiedByImageMagick'. After that i try to re-install imagemagick from https://www.enovate.co.uk/web-design-blog/2015/02/25/how-to-install-imagemagick-from-source-on-ubuntu-14.04/
Imagemagick re-install succeed and open config/application.rb in my rails app
config/application.rb
# add line
Paperclip.options[:command_path] = "/usr/local/bin/identify"
Deploy again

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

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",
}
}
}

Stripe key not set in initializer

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.