How to add a calculated value to an array in rails? - ruby-on-rails-3

I have a Product option that I calculate a weighted score for in Rails.
I'd like to return an array that adds the calculated product score to the array. I tried:
products.inject {|p| p.exponential_discount_score(0.01) }
But got:
NoMethodError: undefined method `exponential_discount_score' for 246.86645269006013:Float
from (irb):39:in `block in irb_binding'
from (irb):39:in `each'
from (irb):39:in `inject'
from (irb):39
from /Users/justin/.rvm/gems/ruby-1.9.2-p290#rails-3.1rc4/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /Users/justin/.rvm/gems/ruby-1.9.2-p290#rails-3.1rc4/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /Users/justin/.rvm/gems/ruby-1.9.2-p290#rails-3.1rc4/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I thought inject would work, but I guess I'm doing something wrong? I also tried .collect but couldn't write the block correctly.

The problem here is that the method you call to calculate score doesn't exist.
When you've created it, you can call something like :
products.collect {|p| p.exponential_discount_score(0.01) }.inject(:+)

Related

Rails/Rack: "ArgumentError: invalid %-encoding" for POST data

Our ruby on rails site has a URI that one of our partners POSTs XML data to.
Since we don't want to deal with XML, we literally just stuff the raw data into a database column and don't go any further with processing it.
However, one of the posts we received gave us this error in airbrake:
ArgumentError: invalid %-encoding ("http://ns.hr-xml.org/2004-08-02"
userId="" password=""><BackgroundReportPackage type="report">
<ProviderReferenceId>....
With backtrace:
vendor/ruby-1.9.3/lib/ruby/1.9.1/uri/common.rb:898:in `decode_www_form_component'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/utils.rb:41:in `unescape'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/utils.rb:94:in `block (2 levels) in parse_nested_query'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/utils.rb:94:in `map'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/utils.rb:94:in `block in parse_nested_query'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/utils.rb:93:in `each'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/utils.rb:93:in `parse_nested_query'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/request.rb:332:in `parse_query'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/request.rb:209:in `POST'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:26:in `method_override'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:14:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/static.rb:63:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:143:in `pass'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:155:in `invalidate'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:71:in `call!'
vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:479:in `call'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:223:in `call'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/deflater.rb:13:in `call'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/rack/log_tailer.rb:17:in `call'
vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:80:in `block in pre_process'
vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:78:in `catch'
vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:78:in `pre_process'
vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:53:in `process'
vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:38:in `receive_data'
vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/backends/base.rb:63:in `start'
vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/server.rb:159:in `start'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/thin.rb:13:in `run'
vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:268:in `start'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
The issue is that the POST contains the data:
<ChargeOrComplaint>DRIVE WHILE BLOOD ALCOHOL LEVEL IS 0.08% OR MORE</ChargeOrComplaint>
Presumably this is valid XML, but the naked % at the end of 0.08% is causing the error, since it's coming via HTTP and I guess rack is expecting it to be URL encoded.
The backtrace indicates this is happening before it even gets to our code, so I don't think it has anything to do with how we're processing it.
My questions, then:
1) Where does the issue lie? Ruby 1.9.3's implementation of decode_www_form_component (at the top of the stack trace)? Rack? Our partner's POST data or headers? Our handling of the POST?
2) Does XML data POSTed via HTTP need to be URL encoded?
3) Is there a header that this POST needs to have for Rack to interpret it correctly? (i.e.: that it's XML binary data, and not URL encoded).
4) If I can't get our partner to change what they're posting to us, how could we work around it? Some Rack middleware?
I'm guessing your partner is probably POSTing the data to you as "x-www-form-urlencoded", making Rack try to parse it that way. If they can change what they're sending, I suspect making their content-type "text/xml" will fix this.
If you can't get them to change what they send, then yes, I think you'd have to use Rack middleware (or monkeypatching). Although you could poke around the Rack source, maybe there's a setting to avoid doing any parsing.
There's some debate in various forums as to where the responsibility lies for catching invalid encoding errors in request body content, but neither rack nor rails handles it, both leaving it to the app to handle. To work around invalid %-encoding in POST data in my app, I used a similar solution to this related question: Rails ArgumentError: invalid %-encoding
I added this middleware in app/middleware/invalid_post_data_interceptor.rb to intercept invalid post data:
class InvalidPostDataInterceptor
def initialize(app)
#app = app
end
def call(env)
request_content = Rack::Request.new(env).POST rescue :bad_form_data
headers = {'Content-Type' => 'text/plain'}
if request_content == :bad_form_data
[400, headers, ['Bad Request']]
else
#app.call(env)
end
end
end
Then added it to the middleware stack by adding this to application.rb:
config.middleware.insert_before Rack::Runtime, "InvalidPostDataInterceptor"
In my case the reason was extra newlines after the headers and before the request body. I'm guessing there is Content-Length inconsistency which throws off the parser. If you are setting headers programmatically make sure they don't have trailing newlines.

How to write a query for searching records and grouping them in ruby on rails via thinking sphinix

I have a Deal model and one Category model having many to many mapping (has_many:through, as i m saving some related data too.)
Also I have a city model which is also having many to many mapping with deal model (Again has_many through)
Category model has no relationship with City model.
Now to search deals based upon keywords (Keywords means, i have indexed some columns like title of the deal, description etc)
#deals = Deal.search(params[:keywords],:per_page => 20, :page => params[:page])
Question is:
Now I need to group these deals based upon the categories, basically first category has 4 deals, second category has 7 deals and so on provided city_id is given.
#deals = #city.deals.search(params[:keywords],:per_page => 20, :page => params[:page])
PS:
You can think of something like this:
End user will enter Select London as a location and then enter "fun" as a keyword and then i need to search the database to check the london deals having having "fun" keyword and group them based upon the various categories.
I hope i am able to explain the question.
EDIT
Some issues with indexing:
rake thinking_sphinx:rebuild --trace
** Invoke thinking_sphinx:rebuild (first_time)
** Invoke thinking_sphinx:app_env (first_time)
** Execute thinking_sphinx:app_env
** Execute thinking_sphinx:rebuild
** Invoke thinking_sphinx:index (first_time)
** Invoke thinking_sphinx:app_env
** Execute thinking_sphinx:index
Generating Configuration to /Users/me/projects/deals/config/development.sphinx.conf
rake aborted!
Cannot automatically map attribute category_ids in Deal to an
equivalent Sphinx type (integer, float, boolean, datetime, string as ordinal).
You could try to explicitly convert the column's value in your define_index
block:
has "CAST(column AS INT)", :type => :integer, :as => :column
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/attribute.rb:334:in `translated_type_from_database'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/attribute.rb:170:in `type'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/attribute.rb:139:in `include_as_association?'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/attribute.rb:107:in `to_select_sql'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/source/sql.rb:69:in `block in sql_select_clause'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/source/sql.rb:69:in `collect'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/source/sql.rb:69:in `sql_select_clause'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/source/sql.rb:19:in `to_sql'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/source.rb:117:in `set_source_sql'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/source.rb:51:in `to_riddle_for_core'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/index.rb:114:in `block in to_riddle_for_core'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/index.rb:113:in `each'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/index.rb:113:in `each_with_index'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/index.rb:113:in `to_riddle_for_core'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/index.rb:83:in `to_riddle'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/active_record.rb:245:in `block in to_riddle'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/active_record.rb:244:in `collect'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/active_record.rb:244:in `to_riddle'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/configuration.rb:164:in `block in generate'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/configuration.rb:161:in `each'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/configuration.rb:161:in `generate'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/configuration.rb:177:in `build'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/tasks.rb:78:in `block (2 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/tasks.rb:95:in `block (2 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/me/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/Users/me/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
Tasks: TOP => thinking_sphinx:index
I supposed that you have a Deal model like
class Deal < ActiveRecord::Base
has_many :category_deals
has_many :categories, :through => :category_deals
has_many :city_deals
has_many :cities, :through => :city_deals
define_index do
indexes :name
has category_deals.category_id, :as => :category_ids
has city_deals.city_id, :as => :city_ids
end
end
So you want to search by city and given category or categories (1,3,2) for the given city with categories ASC order:
Deal.search(params[:keywords], :with => {:category_ids => [1,3,2], :city_ids => params[:city_id]}, :order => "category_ids ASC", :per_page => 20, :page => params[:page])
I'm not entirely sure what you're after - but let's clarify a few things, particularly which results should be returned, and then the order of results.
Firstly, to limit search results to a given city, you'll need the city ids as an attribute in your Deal index definition (speaking of which - it'll help if you can provide the existing define_index block in Deal):
has cities.id, :as => :city_ids
Then, for sorting, it sounds like you want to have search results grouped together by category - but this is tricky, because a deal may belong to more than one category. You can't sort by a MVA attribute (e.g.: the collection of category ids for a given deal). So what exactly do you want to get out of the search results?

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

how to handle Geokit::Geocoders::GeocodeError in rails 3

Hi, I am using Geokit plugin in Ruby on Rails 3, it works fine for me. But when I give origin value not in a proper way it throws Geokit::Geocoders::GeocodeError
Here is my code:
#listing = Listing.geo_scope(:origin=>"sdfaasssssssdfdfsdfdfdfdfsdfsdfsdfsdfsdf")
Error:
Geokit::Geocoders::GeocodeError: Geokit::Geocoders::GeocodeError
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/geokit-1.5.0/lib/geokit/mappable.rb:282:in `normalize'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/geokit-rails3-0.1.2/lib/geokit-rails3/acts_as_mappable.rb:229:in `normalize_point_to_lat_lng'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/geokit-rails3-0.1.2/lib/geokit-rails3/acts_as_mappable.rb:189:in `extract_origin_from_options'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/geokit-rails3-0.1.2/lib/geokit-rails3/acts_as_mappable.rb:111:in `geo_scope'
from (irb):3
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
from D:/ariv/projects/RubyMine/rentstore/script/rails:6:in `require'
from D:/ariv/projects/RubyMine/rentstore/script/rails:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>
How to handle this error?
Thanks,
L. Arivarasan
I dont know what you really mean, but maybe you want something like this
begin
#listing = Listing.geo_scope(:origin=>"sdfaasssssssdfdfsdfdfdfdfsdfsdfsdfsdfsdf")
rescue Geokit::Geocoders::GeocodeError
# handle the error here :-)
end

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.