Title: sunspot index using dynamic attributes
Tags: ruby-on-rails;sunspot
Question: I am trying to integrate sunspot Solr in my Ruby application
I am using dynamic_string for indexing additional data with my model.
However I am getting error
searchable do
text :name
integer :id
text :thumbnail_ref
integer :health_condition_id
dynamic_string :standard_codes, stored: true do
st_codes().inject({}) do |hash, e|
logger.info e.standard
logger.info e.standard_code
hash.merge(e.standard.to_sym =&gt; e.standard_code)
logger.info hash
end
end
def st_codes()
Standard.find_standards_by_health_condition(198)
NoMethodError (undefined method merge' for true:TrueClass):
app/models/content.rb:35:inblock (3 levels) in '
app/models/content.rb:32:in `block (2 levels) in '
I am not clear about this error.Any help here is very much appreciated.


Here is another answer: when you inject you have to return the injected hash for the following iterations.
atm you get a boolean True from logger.info.
change to this
st_codes().inject({}) do |hash, e|
logger.info e.standard
logger.info e.standard_code
hash.merge!(e.standard.to_sym =&gt; e.standard_code)
logger.info hash
hash

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:12/04/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<ruby-on-rails><sunspot>', 'Title': 'sunspot index using dynamic attributes', 'ViewCount': 115, 'id': 47627744, 'user_AboutMe': None, 'user_AccountId': 8899282.0, 'user_DisplayName': 'Anuradha Srivastava', 'user_Reputation': 11.0, 'user_Views': 13.0, 'user_id': 6643205.0}}