I am seeing this error in a delayed job on heroku and it makes no sense to me:
{uninitialized constant Less::Engine
(in /app/app/assets/stylesheets/share_and_earn_recommendation_email.css.less)
/app/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/lib/tilt/css.rb:60:in `prepare'
...
Why no sense? Because css.rb looks like this:
def prepare
if ::Less.const_defined? :Engine
#engine = ::Less::Engine.new(data) # line 60
else
...
Which means it is impossible to hit line 60 if Less::Engine is undefined. What am I missing?
EDIT
Even better demonstration from heroku console:
irb(main):008:0> ::Less.const_defined? :Engine
=> true
irb(main):009:0> ::Less::Engine
NameError: uninitialized constant Less::Engine
EDIT 2
It gets more interesting:
irb(main):011:0> ::Less.const_defined? :Engine, false
=> false
The difference is that the latter does not search ancestors. But there are no ancestors, so it should not make a difference:
irb(main):012:0> ::Less.ancestors
=> [Less]
If you just recently upgraded your rails version within the 3.2.x stack you will find that less is "present" in earlier versions like 3.2.2 and absent in later versions like 3.2.9.
I haven't fully investigated the issue, but I noticed when I went to upgrade from 3.2.2 to 3.2.9, I got some "less" issues.
Cheers
Related
Ran into an interesting scenario today that I'm unsure how to resolve.
Given a rails app with an initializer:
file: config/initializers/integrations.rb
Integrations::CONFIGS = { "key" => "value" }.freeze
If I go into bundle exec rails console and ask for that constant it works as expected:
Integrations::CONFIGS
=> {"key"=> "value"}
Then if I use reload! in the console, I lose that constant:
[2] pry(main)> reload!
Reloading...
=> true
[3] pry(main)> Integrations::CONFIGS
NameError: uninitialized constant Integrations::CONFIGS
from (pry):3:in `<main>'
If I remove the namespace and just have CONFIGS as a constant it works and reloads as expected. I've read through as much of the reload! documentation as I could find and from what I can tell this isn't expected.
My question being, how can I correctly use a namespaced constant in an initializer while also still being able to use reload!?
I am using Sidekiq in one of my projects. Now I need to clear a queue,
the RetrySet, to be more specific.
Following this page from Sidekiq's Github manual, this should work:
Loading development environment (Rails 4.2.1)
>> Sidekiq::RetrySet.new.clear
NameError: uninitialized constant Sidekiq::RetrySet
But it doesn't. Sidekiq itself seems to be loaded:
>> Sidekiq
=> Sidekiq
What am I doing wrong here?
EDIT:
Using Sidekiq version 3.3.4
Looks like you need to require the api library explicitly.
require 'sidekiq/api'
See this for more info https://github.com/mperham/sidekiq/issues/1732
See https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/api.rb#L612
The inheritance explaination
class SortedSet
...
def clear
...
end
end
class JobSet < SortedSet
...
end
class RetrySet < JobSet
...
end
However, In my rails console it worked without needing me to require the library. It was already required. see
> require 'sidekiq/api'
=> false
I use Sidekiq 4.0.1
> Sidekiq::VERSION
=> "4.0.1"
I noticed weird thing developing Spree application (I'm using Spree 1.3.2):
Spree uses model called Zone. Zone is associated with zone_members, like this:
has_many :zone_members, :dependent => :destroy, :class_name => "Spree::ZoneMember"
Strange part begins here, in rails console:
zone = Spree::Zone.first
zone.zone_members.empty?
# => true
zone.zone_members
# => []
zone.zone_members.reload.empty?
# => false
zone.zone_members
# => [#<Spree::ZoneMember id: 4914820, zoneable_id: 13, zoneable_type: ...
What's interesting this problem doesn't occur in Spree 1.3.3.
Apart from Spree, I use Rails 3.2.14 (or Rails 3.2.13 - the same result) and Ruby 1.9.3.
Does anybody know why does it happen?
I would guess that this was a bug that was fixed between Spree 1.3.2 and Spree 1.3.3. I highly recommend using 1.3.3, as that is the latest stable gem release from that branch and probably contains more than just that fix.
What to use as an alternative?
My code..
time = Fixnum.induced_from(minutes_past)
This works on my local but not on my remote Heroku.
Heroku doesn't have this method as a listed method for Fixnums.
As far as I know this method is deprecated in ruby 1.9.x and last existing version where you can you it is 1.8.7. I believe that is a source of your problem.
There are a couple of methods for converting value as instance of Numeric class to value as instance of Fixnum class in 1.9. For example:
1.0.to_i # => 1
1.to_i # => 1
or
Integer(1.0) # => 1
Integer(1) # => 1
I attempted to install the gmaps4rails gem.
I added gem 'gmaps4rails' to my Gemfile, and ran 'bundle install. It said that my bundle installed successfully. I can find "Using gmaps4rails (0.8.8)" with 'gem list'. I added the specified columns to my users table with rake db:migrate and added acts_as_gmappable and the gmaps4rails_address method to my User model.
Visiting pages that involve the user model gives me "undefined local variable or method 'acts_as_gmappable'"error.
Is there something that I am missing?
For greater context, the code I am using is from the Rails 3 Tutorial.
OS X 10.6.6
ruby 1.8.7
rails 3.0.7
passenger 3.0.7
Restarting the server should resolve the problem :)
I had the same issue : undefined local variable or method 'acts_as_gmappable'
I just restarted the server and it error went away.
I was using Mongoid and had the same trouble.
In which case, make sure your model includes:
include Gmaps4rails::ActsAsGmappable
acts_as_gmappable :position => :location
field :gmaps, :type => Boolean
field :location, :type => Array
def gmaps4rails_address
#describe how to retrieve the address from your model, if you use directly a db column, you can dry your code, see wiki
"#{self.address}, #{self.city}, #{self.country}"
end
I think this may be helpful (similar issue):
rvm + rails3 + gmaps4rails - acts_as_gmappable