Rails 4 + Solr: Show search result from different model -


i have search method in controller:

def search   @search = sunspot.search [post, siri]     fulltext params[:q]   end   @posts = @search.results end 

then have in view:

- @posts.each |p|   %h5= p.title 

my question how show separately in view if @posts post model & if @posts siri model.

the reason want seperately because there attr not exists in post model exists in siri model.

thanks in advance!

in class level can use is_a? check if record belongs class:

- if p.is_a? post     // here post model - elsif p.is_a? siri     // here siri model  

if in atrributes level can use respond_to? ruby when object has property return true otherwise false:

- if p.respond_to?(:title)   %h5=p.title 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -