meta_search and acts-as-taggable-on #105

Open
3dfxit opened this Issue Jul 25, 2012 · 0 comments

1 participant

@3dfxit

Hi,

in my project I use meta_search to implement serching in my model

class Picture < ActiveRecord::Base
  include Rails.application.routes.url_helpers
  mount_uploader :avatar, AvatarUploader

  attr_accessor :prefix, :tag_list

  acts_as_ordered_taggable_on :tags

...

end

My controller is:

class PicturesController < ApplicationController

  def index
    if !params[:search].nil?
      @avatarSelected     ||= params[:search][:avatar_like].to_s
      @teggedSelected     ||= params[:search][:tagged_with_like].to_s
    end

    @search = Picture.search(:avatar_or_tag_taggings_tag_name_contains => params[:search])

    @search.meta_sort ||= 'created_at.desc'

    @pictures = @search.paginate(:page => params[:page], :per_page => 20)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @pictures }
    end
  end

My _search.html.erb is:

        <%= form_for @search, :url => pictures_path, :html => {:method => :get} do |f| %>
        <table border="0" width="98%" align="center">
            <tr>
                <td>
                    <%= f.label :avatar_like, "Filename" %>
                    <%= f.text_field :avatar_like, :value => @avatarSelected %>
            </td>
            <td>
                    <%= f.label :tagged_with_like, "Tegged wiith" %>
                    <%= f.text_field :tagged_with_like, :value => @taggedSelected %>
            </td>
          </tr> 
          <tr>
                <td rowspan="2" align="center">
                    <%= f.submit "Find" %>
                </td>
            </tr>
        </table>
        <% end %>

I try the avatar_or_tag_taggings_tag_name_contains to combine a search on picture model witdh taggings, but widthout success.
Can you help me to do this?

Tank in advance
Steve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment