Rails 3 and ar_extensions: undefined method attribute_condition - ruby-on-rails-3

I kept getting this error in my Rails app after upgrading to Rails 3.
>> u.sent_messages
NoMethodError: undefined method `attribute_condition' for #Class:0x105523f18
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/base.rb:1008:in `method_missing'
from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:79:in `sanitize_sql_from_hash'
from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:55:in `each_pair'
from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:55:in `sanitize_sql_from_hash'
from /Library/Ruby/Gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:27:in `sanitize_sql'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/reflection.rb:131:in `send'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/reflection.rb:131:in `sanitized_conditions'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/association_proxy.rb:105:in `conditions'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/has_many_association.rb:103:in `construct_sql'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/association_collection.rb:24:in `initialize'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations/has_many_association.rb:11:in `initialize'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations.rb:1492:in `new'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/associations.rb:1492:in `sent_messages'
from (irb):36
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:488
Turns out I was still using the ar_extensions Gem from http://www.continuousthinking.com/tags/arext. For one thing they have a successor, for another there is a bulk insert option in ActiveRecord now which might be worth checking out (using Model.create([hash1, hash2, hash3, ...])).

ar-extensions is only for use in Rails 2.x. For Rails 3.x you should use the activerecord-import gem. It has the same import API.
https://github.com/zdennis/activerecord-import

Related

Relation#as will change behavior in 4.0. Use `map_to` instead

In hanami guide
https://hanamirb.org/guides/1.2/associations/has-many/#usage
when I use the method
#book = BookRepository.new.find_with_tickets(params[:id])
I got a message:
[deprecated] Relation#as will change behavior in 4.0. Use `map_to` instead
=> Called at:
/Users/saika/Documents/local/kadai-hanami/ticket_api/lib/ticket_api/repositories/book_repository.rb:7:in `find_with_tickets'
/Users/saika/Documents/local/kadai-hanami/ticket_api/apps/api/controllers/books/show.rb:9:in `call'
/Users/saika/.rvm/gems/ruby-2.4.0/gems/hanami-controller-1.2.0/lib/hanami/action/callbacks.rb:195:in `call'
/Users/saika/.rvm/gems/ruby-2.4.0/gems/hanami-controller-1.2.0/lib/hanami/action/callable.rb:71:in `block in call'
/Users/saika/.rvm/gems/ruby-2.4.0/gems/hanami-controller-1.2.0/lib/hanami/action/throwable.rb:145:in `block in _rescue'
/Users/saika/.rvm/gems/ruby-2.4.0/gems/hanami-controller-1.2.0/lib/hanami/action/throwable.rb:143:in `catch'
I do not know what should I instead use 'map_to'.
you should replace #as with #map_to, and it will work as usual.

ThinkingSphinx Error: such filter attribute

I am trying to integrate ThinkingSphinx into my project using the doc. For a User model with attributes first_name and last_name I have created the indexes as:
User.rb
define_index do
indexes :first_name
indexes :last_name
end
Then I run the commands:
rake ts:index
rake ts:start
This starts my search. I get the results when I use the following command to search:
User.search('swati')
But When I run
User.search :with => {:first_name => "swati"}
It gives me the error:
Sphinx Sphinx Daemon returned error: index user_core: no such filter attribute 'first_name'
Sphinx Caught Sphinx exception: index user_core: no such filter attribute 'first_name' (0 tries left)
ThinkingSphinx::SphinxError: index user_core: no such filter attribute 'first_name'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:438:in `block in populate'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:606:in `call'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:606:in `retry_on_stale_index'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:426:in `populate'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:187:in `method_missing'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I searched for a possible solution on stackoverflow and it has been asked to run the commands rake ts:index and rake ts:rebuild. I have run this commands but it didn't help me.
Please help me figure out a solution for this.
Many thanks.
You should create an attribute with has in the index, rebuild, and then use with
has :first_name
Has creates an attribute, and with is used as a filter (for attributes) http://pat.github.com/ts/en/searching.html#filters
Also check http://pat.github.com/ts/en/indexing.html#attributes for filters.
Be carefull, rake ts:reindex and rake ts:rebuild are different.
If you add a new index, you need to rebuild.
If you are paranoiac like me, try everything:
rake ts:rebuild
rake ts:reindex
rake ts:restart
If it still doesn't work, make sure your index is defined properly.

Rails 3 NoMethodError: undefined method

All of a sudden I started to get two different errors with one of my Models. I have no idea what I changed, but my code doesn't seem to be the problem.
I entered the rails console. I typed QuestiNon.find(:all) and I got all the records I have entered so far. But, if I try
ruby-1.8.7-p352 :003 > Question.find(55)
NoMethodError: undefined method `eq' for nil:NilClass
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.0.10/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/activerecord-3.0.10/lib/active_record/relation/finder_methods.rb:299:in `find_one'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/activerecord-3.0.10/lib/active_record/relation/finder_methods.rb:289:in `find_with_ids'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/activerecord-3.0.10/lib/active_record/relation/finder_methods.rb:107:in `find'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/activerecord-3.0.10/lib/active_record/base.rb:444:in `__send__'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/activerecord-3.0.10/lib/active_record/base.rb:444:in `find'
from (irb):3
I have double checked and the id 55 does exist
And if I try the create method I get:
ruby-1.8.7-p352 :004 > Question.create("question" => "something")
NoMethodError: undefined method `name' for nil:NilClass
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.0.10/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:56:in `visit_Arel_Nodes_InsertStatement'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:55:in `map'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:55:in `visit_Arel_Nodes_InsertStatement'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.10/lib/arel/visitors/visitor.rb:15:in `send'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.10/lib/arel/visitors/visitor.rb:15:in `visit'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.10/lib/arel/visitors/visitor.rb:5:in `accept'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:18:in `accept'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:111:in `with_connection'
from /home/mari/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.10/lib/arel/visitors/to_sql.rb:16:in `accept'
Googling around some people suggested the problem is due to a primary_key configuration, but I have not set a new primary key. My models primary key should be id.
My question.rb is like this:
class Question < ActiveRecord::Base
set_table_name "questions"
end
and my table is like this:
from (irb):4ruby-1.8.7-p352 :005 > ActiveRecord::Base.connection.columns("questions").map{|c| [c.name, c.type] }
=> [["id", :integer], ["question_type", :integer], ["question", :string], ["mandatory", :boolean], ["help", :string], ["answers", :string], ["question_number", :integer], ["survey_id", :string], ["created_at", :datetime], ["updated_at", :datetime]]
The weird thing is that this is working fine in my server with MYSQL, but locally with SQLITE3 it is not.
How can I fix this? Any ideas? Thanks.

integrating facebook login with restful authentication for rails 3x

"some blog and stack-overflow even says that rails 3 dont have work with rails3 for restful-authentication", it may be older posts.
So I've gone through several tutorials but nothing found to be working.
the error on:
Macbook:Project user$ rails generate xd_receiver
Could not find generator xd_receiver.
so i found the errors and try to fix it but it will prompt for other errors.
And Then found some update for restful-authentication to work with facebook login,
It also cant fix the errors.
then error on:
Macbook:Project user$ rails generate xd_receiver
/Sha/Todayswork/Ruby On Rails/Project/vendor/plugins/facebooker/lib/facebooker/adapters/adapter_base.rb:6:in <class:Adapter
Base>': uninitialized constant ActiveSupport::CoreExtensions (NameError)
from /Sha/Todayswork/Ruby On Rails/Project/vendor/plugins/facebooker/lib/facebooker/adapters/adapter_base.rb:3:in<
module:Facebooker>'
from /Sha/Todayswork/Ruby On Rails/Project/vendor/plugins/facebooker/lib/facebooker/adapters/adapter_base.rb:1:in <
top (required)>'
from /Sha/Todayswork/Ruby On Rails/Project/vendor/plugins/facebooker/lib/facebooker.rb:259:in'
from /Sha/Todayswork/Ruby On Rails/Project/vendor/plugins/facebooker/init.rb:5:in <top (required)>'
from /Sha/Todayswork/Ruby On Rails/Project/vendor/plugins/facebooker/rails/init.rb:1:inblock in '
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/plugin.rb:81:in eval'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/plugin.rb:81:inblock in '
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/initializable.rb:25:in instance_exec'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/initializable.rb:25:inrun'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/initializable.rb:50:in block in run_initializ
ers'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/initializable.rb:49:ineach'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/initializable.rb:49:in run_initializers'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/application.rb:134:ininitialize!'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/application.rb:77:in method_missing'
from /Sha/Todayswork/Ruby On Rails/Project/config/environment.rb:5:in'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/application.rb:103:in require'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/application.rb:103:inrequire_environment!'
from /Users/user/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.0/lib/rails/commands.rb:16:in <top (required)>'
from script/rails:6:inrequire'
from script/rails:6:in `'
Thanks for any response,
And
Any help would be greatly appreciated.
would look into OmniAuth. just used and was painless to integrate. See railscasts for simple auth with OmniAuth

MongoMapper won't let me create an object

I'm just learning MongoDB and MongoMapper. This is on Rails 3.
I created a blog in app/models/blog.rb:
class Blog
include MongoMapper::Document
key :title, String, :required => true
key :body, Text
timestamps!
end
I go into the Rails console:
rails c
Loading development environment (Rails 3.0.0.beta)
ruby-1.9.1-p378 > b = Blog.new
NoMethodError: undefined method `from_mongo' for Text:Module
from /Users/jade/.rvm/gems/ruby-1.9.1-p378/gems/mongo_mapper-0.7.2/lib/mongo_mapper/plugins/keys.rb:323:in `get'
from /Users/jade/.rvm/gems/ruby-1.9.1-p378/gems/mongo_mapper-0.7.2/lib/mongo_mapper/plugins/keys.rb:269:in `read_key'
from /Users/jade/.rvm/gems/ruby-1.9.1-p378/gems/mongo_mapper-0.7.2/lib/mongo_mapper/plugins/keys.rb:224:in `[]'
from /Users/jade/.rvm/gems/ruby-1.9.1-p378/gems/mongo_mapper-0.7.2/lib/mongo_mapper/plugins/inspect.rb:7:in `block in inspect'
from /Users/jade/.rvm/gems/ruby-1.9.1-p378/gems/mongo_mapper-0.7.2/lib/mongo_mapper/plugins/inspect.rb:6:in `collect'
from /Users/jade/.rvm/gems/ruby-1.9.1-p378/gems/mongo_mapper-0.7.2/lib/mongo_mapper/plugins/inspect.rb:6:in `inspect'
from /Users/jade/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta/lib/rails/commands/console.rb:47:in `start'
from /Users/jade/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta/lib/rails/commands/console.rb:8:in `start'
from /Users/jade/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta/lib/rails/commands.rb:34:in `<top (required)>'
from /Users/jade/code/farmerjade/script/rails:10:in `require'
from /Users/jade/code/farmerjade/script/rails:10:in `<main>'
Am I overlooking something really dumb, or is this something in my setup?
I'm using the mongo_mapper version you get by adding it to your Gemfile, so I'm wondering if it might be that. I'd appreciate any suggestions!
As I suspected, this was a silly mistake. I was using Text instead of String, and Mongo doesn't natively support Text as a key. If you define a from_mongo method, it would.
Thanks to DanP on IRC for pointing out my error.