I'm pretty new to rails and mongoid and I have a problem with extracting a string out of a query.
I have a class Filteroption
class Fieldoption
include Mongoid::Documentfield :name, :type => String field :option_id, :type => Integerend
and with this entries
+--------------------------+------------------------------------+-----------+ | _id | name | option_id | +--------------------------+------------------------------------+-----------+ | 4c6de6a11d41c86698000002 | Request URI | 1 | | 4c6de6a11d41c86698000003 | Hostname | 4 |
When 开发者_StackOverflow社区I query for the name with the option_id 4
foobar = Fieldoption.only(:name).where(:option_id => '4')
foobar.name should be "Hostname". Instead I get
foobar.name
=> "Fieldoption"
What am I doing wrong ?
Thanks for your help.
The name method is already defined in Ruby to get the class name. You should rename your field to be able to get its content, or try foobar.attributes["name"].
加载中,请稍侯......
精彩评论