Using the serialize_with_options gem in rails 3 application.
gemfile
gem 'serialize_with_options'
in model (User.rb)
serialize_with_options(:less) do
only :id, :name
end
there is an exception thrown when application is booted:
NoMethodError: undefined method `serialize_with_options' for User
any clue why/how rails is not loading gem?
Related
I have created a fresh rails project. It's running on the lastest rails version as i have just installed rails on my pc and it is using Postgre for the DB. I have added the gem 'geocoder' in the gemfile and bundle install it. I have create a scaffold rails g scaffold location address:string latitude:float longtiude:float
I have added the following code into the location model file which I got from the official geocoder website http://www.rubygeocoder.com/
reverse_geocoded_by :latitude, :longitude,
:address => :location
after_validation :reverse_geocode
I then tried testing it, however it doesn't work. I have tried looking and reading the documentation but couldn't find any useful information. Could someone help pls.
I am getting the error of undefined method `location ....' when trying to save. This error is shown in the def create function
Parameters:
{"authenticity_token"=>"[FILTERED]", "location"=>{"address"=>"",
"latitude"=>"48.8582", "longitude"=>"2.2945"}, "commit"=>"Create
Location"}
I am using the following commond
gem 'carrierwave'
bundle
rails generate uploader image
mount_uploader :image, ImageUploader
but it gives the errors
NoMethodError in PostsController#index
undefined method `mount_uploader' for Post:Class Extracted source
(around line #8):
line #8: mount_uploader :image, ImageUploader
end
I think your problem is you are using the wrong gem, for mongodb using mongoid ORM you should use the following gem,
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
If you install this you problem should get solved.
I am using 'acts_as_messagable' gem for private messaging between users.
My model:
class User < ActiveRecord::Base
acts_as_messageable :table_name => "messages"
..
end
I have error on start application:
`method_missing': protected method `default_scope' called for #<Class:0x007f84d7870da8> (NoMethodError)
current rails version 4.1, migrations are done.
What is the root of problem?
It's not compatible from the docs:
the gem is compatible with Rails 2.3, an upgrade to Rails 3 is planned
My implementation was working with rails version 3.2. I am trying to upgrade my app to rails 4.1 but then I started getting error "uninitialized constant ActiveRecord::Transitions". According to transitions gem documentation on github (https://github.com/troessner/transitions) , it should work with rails >=4 without any issue.
code for active_record class with transitions is given below.
class Coupon < ActiveRecord::Base
has_paper_trail
include Rails.application.routes.url_helpers
include ActiveRecord::Transitions
state_machine do
state :available
state :issued
event :issue do
transitions :to => :issued, :from => :available
end
end
end
error I am getting is
`<class:Coupon>': uninitialized constant ActiveRecord::Transitions (NameError)
Although gem is included
gem "transitions", :require => ["transitions", "active_model/transitions"]
The docs say to include ActiveModel::Transitions. What you have done is include ActiveRecord::Transitions.
Typo maybe??
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