Hi All, I'm having trouble getting the 
acts-as-taggable-on<https://github.com/mbleigh/acts-as-taggable-on>gem's 
results filtered correctly, and I think that the answer is 
straightforward for someone who knows what they are doing.  So I'm hoping 
someone can help me.  

I have two models: users and recipes. Recipes is the model that 
acts_as_taggable with two contexts.

*user.rb*

class User < ActiveRecord::Base
  acts_as_tagger
  has_many :receipes
end

*recipe.rb*

class Recipe < ActiveRecord::Base
  acts_as_taggable
  acts_as_taggable_on :ingredients, :descriptions

  has_one :user

end

*recipe helper*

module RecipesHelper
  include ActsAsTaggableOn::TagsHelper
end

*the controller* - this is meant to show a tag cloud (@tags), and then if a 
tag is selected, the page reloads filtering out words based on the user and 
the tag

  def index
    @user = current_user 
    @tags = User.find_by_id(current_user).recipes.tag_counts_on(:ingredients)

    if params[:tag]
      @recipes = Recipe.tagged_with(params[:tag])
    else
      @recipes = Recipe.where("user_id =?", @user)
    end
  end

The issue I'm having is that the results are filtered out by tag, but 
doesn't take in consideration the user or the context. For example, if the 
tag is "chicken", it will show the results whether the tag is an 
ingredients or descriptions tag, and it will show for all users.

I have tried to replace this line in the controller:

@recipes = Recipe.tagged_with(params[:tag])

with each, these variations to no avail:

(1) Filters the results by user, but doesn't distinguish between 
ingredients or descriptions tag

@recipes = User.find_by_id(current_user).recipes.tagged_with(params[:tag])

(2) Yields undefined method "set_owner_tag_list_on" for 
#<ActiveRecord::Relation:0x42d9320>

@tagged_recipes = 
User.find_by_id(current_user).recipes.tagged_with(params[:tag])
@user.tag(@tagged_recipes, :with => (params[:tag]), :on => :ingredients)

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/eW4IHC5tsXIJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to