Fixnum doesn't have an "induced_from" method on Heroku - ruby-on-rails

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

Related

Use ActiveSupport::Cache::FileStore directly in a model class

I tried to use ActiveSupport::Cache::FileStore dirctly in a model class:
#backend_cache = ActiveSupport::Cache::FileCache.new Rails.root.join("tmp", "cache")
The program reports a NameError
NameError: uninitialized constant ActiveSupport::Cache::FileCache
Did you mean? FileTest
I added
require "active_support"
require "active_support/core_ext"
It still shows the error. I know that I can use Rails.Cache for the purpose, but the object I cached must be on the disk, which is different from other parts of the application.
The application is written in Rails 6.
I tried this inside a rails 6 console and it works just fine.
#backend_cache = ActiveSupport::Cache::FileStore.new(Rails.root.join("tmp", "cache"))
#backend_cache.write('x', 1) # => true
#backend_cache.read('x') # => 1
It's just typo I mentioned in the comment. It's ::FileStore.new instead of ::FileCache.new

Cannot override core ruby class in Rails 2.3.4

I want to extend the ruby class, for example,
# lib/core_ext/hash.rb
class Hash
def gop_compact
delete_if{|k, v| (k.blank? || v.blank?)}
end
end
I have created a separate folder in the /lib directory as follows,
lib/core_ext/hash.rb
And I tried to include this path in load_paths as follows,
# config/environment.rb
config.load_paths += %W( #{RAILS_ROOT}/lib/core_ext )
After all this setup, restarted the server and tried calling method on a Hash object but it throws an undefined method exception.
Note:- Rails version is 2.3.4
I spent lot of time on this but no luck yet. Any help is appreciated.
Thanks in advance!
Even though you've added the core_ext folder to your load paths, you'll still need to require it with require 'hash'. To minimize memory usage, Rails won't actually require ruby files just because you add them to your load_path.
>> Hash.instance_methods.grep(/gop/)
=> []
>> require "hash"
=> true
>> Hash.instance_methods.grep(/gop/)
=> [:gop_compact]

Rails 3.2.8, heroku: uninitialized constant Less::Engine

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

undefined local variable or method 'acts_as_gmappable'

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

will_paginate works on local box, gives "undefined method to_i" on server but both point to the same database

We just ran into this problem the other day all of a sudden. Our Rails app is using will_paginate, and I have it defined as follows in my controller:
# contacts_controller.rb
def index
# ...
#search = #current_user.contacts.search(params[:search])
#contacts = #search.all.paginate({:page => params[:page], :per_page => 20})
end
Both development and staging (this is a staging box not production) point to the same database. The above code works fine on my local machine, however on staging I get the following error:
undefined method 'to_i' for {:per_page=>20, :page=>nil}:Hash
The code is identical on both computers. Any idea why it works fine on one and not on the other?
EDIT: On the staging server I was using the plugin while on my local box I was using the gem, however I removed the plugin and installed the gem and now I get an error that says:
uninitialized constant Array::WillPaginate
Evidently it is still not solved.. after doing a deploy on the staging server I'm getting that error again, despite the fact that it was working before fine. Anyone have any ideas at all on this? I'm totally clueless.
If the page param is nil, it's often a good idea to default to a value of 1. This covers cases where no url parameter for page is passed. Where a parameter is passed, it will be used in place of the default:
{:page => params[:page] || 1, :per_page => 20})
Full example:
# contacts_controller.rb
def index
# ...
#search = #current_user.contacts.search(params[:search])
#contacts = #search.all.paginate({:page => params[:page] || 1, :per_page => 20})
end
Well, I seem to have solved it:
I had to explicitly type require 'will_paginate' in the environment after I uninstalled the plugin and installed the gem. However I'm still not sure why the plugin was working on my local machine but not on staging.

Resources