Filtering acts-as-taggable-on Results in Rails

Hi All, I’m having trouble getting the
acts-as-taggable-onhttps://github.com/mbleigh/acts-as-taggable-ongem’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)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs