I have the next error and I don't know how to resolve, I'm using rails 4.1 and ruby 2.1.3
the problem is with my locale file, I have app with portuguese language for default and I translate all the file necessaries, and in my local is right no problem but when do
heroku run rake db:migrate
I have the next error:
Running rake db:migrate attached to terminal... up, run.5369 rake
aborted! I18n::InvalidLocale: :es is not a valid locale
/app/vendor/bundle/ruby/2.1.0/gems/i18n-0.7.0.beta1/lib/i18n.rb:284:in
enforce_available_locales!'
/app/vendor/bundle/ruby/2.1.0/gems/i18n-0.7.0.beta1/lib/i18n/config.rb:34:in
default_locale='
/app/vendor/bundle/ruby/2.1.0/gems/i18n-0.7.0.beta1/lib/i18n.rb:35:in
default_locale=' /app/config/environments/production.rb:75:inblock
in '
I have a locale file and is :
I18n.load_path += Dir[Rails.root.join('lib', 'locales', '*.{rb,yml}')]
I18n.load_path += Dir[Rails.root.join('config', 'locales', '**',
'*.{rb,yml}')]
I18n.available_locales = Dir[Rails.root.join('config', 'locales',
'*.{yml}')].collect {|l| locale = l.scan(/.+/(..).yml/)[0];
locale[0].to_sym unless locale.nil?}.delete_if {|locale| locale.nil?}
I18n.default_locale = [:en, :es] I18n.config.enforce_available_locales
= true
also in production.rb have :
I18n.default_locale = :es
I try all the options possibles but I don't have solution
Thanks for the time !!
the solution for this problem is really easy and you need add in your application.rb this code:
I18n.enforce_available_locales = false
Regards !
Related
I'm trying to deploy my sinatra on Heroku https://www.heroku.com/home
I was successful before I tried post method which gave me 404
Get methods work fine:
here is the example of the code:
get '/getPriceList' do //no error, everything works fine
content_type :json, charset: 'utf-8'
today_menu.to_json
end
post '/makeOrder', provides: :json do //error NOT FOUND
data = request.env['rack.input'].read
parsed_data = JSON.parse data.force_encoding('UTF-8')
if User.where(:name => parsed_data['userName']).first.nil?
current = Time.now
fixed = Time.local(current.year, current.month, current.day, 18, 40, 0)
if current > fixed
ObedResponse.new(data, false, 'Vi ne uspeli').to_json
else
#user = User.create(:name => parsed_data['userName'])
#some stuff
end
ObedResponse.new(data, true, "").to_json
end
else
ObedResponse.new(data, false, 'Сегодня вы уже заказали').to_json
end
Can someone tell me why I'm getting this error and how to make the thing work?
PS: I don't have this error while deploying locally using
bundle exec ruby obed.rb -e production
to start
I was in the wrong branch when I commited into Heroku. Changing the branch to master solved the issue.
I am following the very basic tutorial found here: http://guides.rubygems.org/make-your-own-gem/
hola_username.rb:
class Hola
def self.hi
puts "Hello world!"
end
end
hola_username.gemspec:
Gem::Specification.new do |s|
s.name = 'hola_username'
s.version = '0.0.0'
s.date = '2010-04-28'
s.summary = "Hola!"
s.description = "A simple hello world gem"
s.authors = ["Surname Lastname"]
s.email = 'me.me#gmail.com'
s.files = ["lib/hola_username.rb"]
s.homepage =
'http://rubygems.org/gems/hola_username'
s.license = 'MIT'
end
That really is all there is to the project.
I can build my gem with
gem build .\hola_username.gemspec
I have also tested it by importing and executing the hi function of the Hola class and it works:
PS E:\hola_username> gem install .\hola_username-0.0.0.gem
Successfully installed hola_username-0.0.0
Parsing documentation for hola_username-0.0.0
Done installing documentation for hola_username after 0 seconds
1 gem installed
&
irb(main):001:0> require 'hola_username'
=> true
irb(main):002:0> Hola.hi
Hello world!
=> nil
irb(main):003:0>
But when I try to
gem push .\hola_username-0.0.0.gem
I get:
ERROR: While executing gem ... (Psych::SyntaxError)
(): control characters are not allowed at line 1 column 1
Any ideas?
Edit: I am on a windows 10 machine using ruby 2.0.0p598
Edit v01: Anything I put after gem push will result in the above error, doesn't seem to be a problem with the sample rubygem.
Edit v02: My credentials file that was generated in the .gem folder however stars with hex characters: fffe2d002d00.. Which might be the ones causing trouble?
My credentials file in .gem folder was encoded with UCS2 - Little Endian and converting it to UTF without BOM did the trick.
Although I have absolutey no idea why..
I am trying to run Phusion Passenger and this is the furthest I got. When it loads up on the website it comes up
require 'rails/all'... 0.550s
Bundler.require... 1.510s
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Application.initialize!... !> Error
Where do I put I18n.enforce_available_locales = false and will this solve my issue?
I doubt it will solve the error.
You need to put
I18n.enforce_available_locales = false
into your application.rb file so that it looks like this
...
module FoodDump
class Application < Rails::Application
...
I18n.enforce_available_locales = false
...
end
end
I'm running Rails 3.2 and the latest version of Authlogic. When I run my app locally on my Mac, it works fine. When I try to run it on my production server (Ubuntu with Passenger/Apache), I get this:
You must establish a database connection before using acts_as_authentic
I'm not sure how to troubleshoot the problem. I posted this related question earlier today before I realized that the problem was broader than I thought.
I figured out the problem. Look at this snippet from Authlogic's lib/authlogic/acts_as_authentic/base.rb:
private
def db_setup?
begin
column_names
true
rescue Exception
false
end
end
If column_names throws an error, db_setup? will return false. Look at this other function, also from base.rb:
def acts_as_authentic(unsupported_options = nil, &block)
# Stop all configuration if the DB is not set up
raise StandardError.new("You must establish a database connection before using acts_as_authentic") if !db_setup?
raise ArgumentError.new("You are using the old v1.X.X configuration method for Authlogic. Instead of " +
"passing a hash of configuration options to acts_as_authentic, pass a block: acts_as_authentic { |c| c.my_option = my_value }") if !unsupported_options.nil?
yield self if block_given?
acts_as_authentic_modules.each { |mod| include mod }
end
If db_setup? returns false, Authlogic will throw an exception, but not the same exception thrown by column_names.
My problem was that column_names was throwing this exception:
/Users/jason/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `async_exec': PG::Error: ERROR: relation "users" does not exist (ActiveRecord::StatementInvalid)
LINE 4: WHERE a.attrelid = '"users"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
And the reason for THAT exception is that my user table is called user, not users, but Rails was not picking up on my pluralize_table_names setting properly. Once I fixed my pluralize_table_names problem (apparently the way this setting works has been changed in Rails 3.1), my Authlogic problem went away.
So if you're having this problem, you might want to try this:
Clone the Authlogic repo to somewhere on your dev machine
Change your Gemfile to use the local version of Authlogic ('authlogic', :path => '/path/to/authlogic')
Add a column_names call to db_setup? outside the begin/rescue/end clause
See if you get a different, potentially more accurate and informative, error, like I did
I've fixed this on my fork. Until Ben has time to merge the fix you can work around this using the fixed branch in your Gemfile;
gem 'authlogic', :git => 'git#github.com:james2m/authlogic.git', :branch => 'fix-migrations'
For anyone else who might have come to this page looking for an answer.
One reason could be that your haven't created your test database.
Just run:
$ RAILS_ENV=test rake db:create db:migrate
Follow the open issue at https://github.com/binarylogic/authlogic/issues/318 and +1 so the fix gets merged soon :)
I'm building a rake task that pulls down a repo, runs some specs and builds a gem if they all pass.
The gemspec file comes with the original checkout of the repo, and I'd like to bump the version whenever the gem is built (i.e. when the task is run). Gem::Specification.load doesn't let me manipulate the attributes of the gemspec since it just returns nil. The only way I've figured out to do this so far is to create a temp gemspec, replace the version line with what I want and mv it over the current gemspec.
However, the file is not updated until (I think) the process exits. The path and file are nominally there, but there is no content in the file itself, it's just blank. When testing in irb, the gemspec's content appears after exiting the session.
Here's the rake task for gem building:
desc "Build new vulnerability tests gem"
task :build_gem do
Process.fork { update_gemspec_version 'foo.gemspec' }
gemspec = Gem::Specification.load('foo.gemspec')
builder = Gem::Builder.new(gemspec)
puts "Building gem from #{gemspec.file_name}"
builder.build
end
(You can see I thought forking the process to run the method would fix the problem, but it just used the original gemspec to build the gem and didn't update anything until the rake task completed.)
And the update_gemspec_version helper method:
def update_gemspec_version(gemspec)
temp_file = Tempfile.new "#{gemspec}"
time = Time.now
minor_rev = 0
base = time.year.to_s + '.' + time.month.to_s + '.' + time.day.to_s
File.open("#{gemspec}", 'r') do |file|
file.each do |line|
if line =~ /^\s*s\.version\s=\s'(\d+\.\d+\.\d+\.(\d+))'$/
if $1 >= base + '.' + minor_rev.to_s
while minor_rev <= $2.to_i
minor_rev += 1
end
replacement = line.gsub($1, base + '.' + minor_rev.to_s)
puts replacement
temp_file.puts replacement
else
replacement = line.gsub($1, base + '.' + minor_rev.to_s)
puts replacement
temp_file.puts replacement
end
else
temp_file.puts line
end
end
end
FileUtils.mv(temp_file.path, File.expand_path("#{gemspec}"))
nil
end
Am I going about this all wrong?
Gem::Specification.load doesn't let me manipulate the attributes of
the gemspec since it just returns nil.
Are you using the latest RubyGems? Gem::Specification.load returns an instance of Gem::Specification if it evaluates the gem spec file successfully... maybe a typo? See https://github.com/rubygems/rubygems/blob/master/lib/rubygems/specification.rb