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
Related
I am following the directions from the gem's GitHub repo:
I added fuzzily to my gem file and ran rake db:install. Fuzzily 0.3.3 was successfully installed.
I created a app/models/fuzzily.rb file:
class Trigram < ActiveRecord::Base
include Fuzzily::Model
end
I then created a migration for it:
class AddTrigramModel < ActiveRecord::Migration
extend Fuzzily::Migration
end
And ran: rake db:migrate, which created a trigrams table with the fields: id, trigram, score, owner_id, owner_type, fuzzy_field
I then modified my app/models/organization.rb and added the following:
fuzzily_searchable :org_name
I saved all my work and started the console:
rails c
then:
Lobbyist.connection
Followed by:
Lobbyist.bulk_update_fuzzy_name
To which I am getting an error message: undefined method .bulk_update_fuzzy_name
My environment is:
Ruby 2.1.5
Rails 4.2.1
Any ideas?
The name part in bulk_update_fuzzy_name is actually the name of the searchable field, so in your case it would be Lobbyist.bulk_update_fuzzy_org_name. The same applies to other method calls in the readme.
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
Does anyone know why this callback method would work in Rails 2.3.x / Ruby 1.8.7 but not in Rails 3.0.x / Ruby 1.9.2?
Works in Rails 2.3.x / Ruby 1.8.7:
class Post < ActiveRecord::Base
after_create :destroy_old_posts
acts_as_taggable
# ...
protected
def destroy_old_posts
self.tag_list.each do |tag|
posts = Post.find_tagged_with(tag, :order => 'updated_at DESC')
posts[19..-1].each {|p| p.destroy } if posts.size >= 20
end
end
end
But with 3.0.x / Ruby 1.9.2 I receive the following error upon creating a post:
undefined method `find_tagged_with' for #<Class:0x00000002943048>
app/models/post.rb:30:in `block in destroy_old_posts'
app/models/post.rb:29:in `each'
app/models/post.rb:29:in `destroy_old_posts'
app/controllers/posts_controller.rb:29:in `block in create'
app/controllers/posts_controller.rb:28:in `create'
I'm using acts-as-taggable-on 2.0.6. Thank you for reading my question.
I believe the correct usage is Post.tagged_with
I'm reading the book Learning Rails by O'Reilly and it recommends using the validate_existence_of plugin. When I run:
ruby script/plugin install http: //svn.hasmanythrough.com/public/plugins/validates_existence/
it says it's already installed, but when I use it, I get a message saying:
NoMethodError in AwardsController#index
undefined method `validates_existence_of' for #<Class:0xb5fde868>
When I say:
class Award < ActiveRecord::Base
belongs_to :student
validates_existence_of :student
end
Any ideas?
Have you checked that the plugin code is installed in the vendor/plugins directory ?
Also you may need to check that the environment.rb file has the config.gem section uncommented.