This is my first question, and hopefully someone can help.
class Post < ActiveRecord::Base
acts_as_mappable :distance_field_name => :distance
class Category < ActiveRecord::Base
and, of course, the join table: categories_posts
The following find works and is paginated via will_paginate:
results = Post.paginate(:page => page,
:origin => user,
:conditions => [‘removed_at IS NULL AND zip = ?
AND intention = ? AND title like ?’,
:order => ‘date_format(updated_at,"%Y%m%d") DESC,
) if search.blank?
search — the query enter by the user
search_type — selected by the user from [‘offered’, ‘wanted’]
removed_at — date/time post was made invisible
zip – posts.zip
intention – posts.intention is either offered or wanted matches
:origin => user — references the current user’s latitude/longitude
which calculates a distance column (i.e.
distance of post from current user)
The search needs to include only rows that also match one or more
I have tried :join and :include(this can’t have conditions), but I
can’t seem to make it work properly.
note: the results can be read-only as it’s just a search
If I used find_by_sql I think I would lose acts_as_mappable(GeoKit)
and will_paginate functionality.
Any help or suggestions would be greatly appreciated.