Need help getting ahold of highlight property when using Tire gem


(Meltemi) #1

I'm having a hard time getting ahold of the highlight property in my Rails
app. I know the highlight is being return because it's present in curl
results that I get from raise to_curl.

Simple controller:

def index
@reports = Report.search(params)
end

Simple model:

def self.search(params)
tire.search do
query { string params[:query] } if params[:query].present?
highlight :attachment
# raise to_curl
end
end

Simple *view *(haml):

  • @reports.each do |report|

    - @reports.results.each do |report| # <== doesn't work either

    • if report.respond_to?(:highlight)
      = raw report.highlight.attachment.first.to_s
    • else
      = "broken!" # <=== only ever see this
      ...

Abbreviated curl response from raise to_curl in model (FWIW):
https://gist.github.com/3707560

What am I missing?!? What's the proper way of getting ahold of the
'highlight' string associated with each record? I know I'm overlooking the
painfully obvious. Thanks!

--


(Meltemi) #2

In my troubleshooting I think I may have made this more difficult than it
needed to be by adding faulty 'responds_to?' check.

= raw report.highlight.attachment.first.to_s

seems to work. Still love to hear/see if someone has a better way.

--


(system) #3