Peter Tellgren wrote:
> here is what I have so far not working... (quite new to rails)
> index.html.erb
>     <% for tag in Tag.find(:all, :order => "name asc") %>
>             <%= check_box_tag 'tag_ids[]', tag.id, false %> #should be
> checked according to sent params.
>             <%=h tag.name %>
>         <% end %>
> 
> books.rb
>  # attributes
>     has author.taggings.tag(:id), :as => :tag_ids
> 
> search_controller.rb
>  @books = Book.search params[:q], :conditions => { :tag_ids =>
> params[:tag_ids] }

How is this approach not working?

The basic technique should be valid, however:

Check the value of params[:tag_ids] in your controller to ensure
it contains the tag ids you expect.

Do you want all books that match any of the tags (an OR query) or books
that match all the tags (an AND query)?

The default is OR, if you want an AND query, try:

    Book.search params[:q], :with_all => { :tag_ids => params[:tag_ids] }

-- James Healy <jimmy-at-deefa-dot-com>  Wed, 15 Apr 2009 20:42:39 +1000

Attachment: signature.asc
Description: Digital signature

Reply via email to