[Rails] Re: How do I sort my columns inside my AJAX search result?
Anders Andrew wrote in post #1065829:
> Radhames Brito wrote in post #1065828:
>>>
>> if @search is not an ActiveRecord::Relation object you cant chain it
>> with
>> another ActiveRecord::Relation object. What class does the search
>> function
>> returns? are you using a gem? the search function could be returning an
>> array in which case you have to build your own sorting mechanism.
>
> Hi rbritom.
>
> I am using the sunspot_rails gem (https://github.com/sunspot/sunspot).
>
> My old search function (and sorting function) was build after Railscast
> 240 (http://railscasts.com/episodes/240-search-sort-paginate-with-ajax),
> but as I needed to search through multiple columns I implemented Sunspot
> instead. Not quite sure if @search is an ActiveRecord::Relation. Fairly
> new to Rails.
When I look around on the internet I can see that people uses sort_by to
make it work, e.g.:
def index
@user = current_user
@search = @user.products.search do
fulltext params[:search]
order_by sort_column, sort_direction
end
@products = @search.results
end
However it stil breaks. With this error message:
Sunspot::UnrecognizedFieldError in ProductsController#index
No field configured for Product with name 'name'
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home