mbleigh / acts-as-taggable-on
- Source
- Commits
- Network (90)
- Issues (9)
- Downloads (7)
- Wiki (1)
- Graphs
-
Branch:
master
-
If I call tagged_with without specifying options, I get an exception thrown:
ArgumentError: wrong number of arguments (1 for 2)
from vendor/plugins/acts-as-taggable-on/lib/acts_as_taggable_on/acts_as_taggable_on.rb:90I just installed the plugin today; this is a Rails 2.3.2 project.
Here's my proposed patch:
named_scope :tagged_with, lambda{ |tags, *options| options = options.shift || {} find_options_for_find_tagged_with(tags, options) }Comments
-
Hi,
This a great plugin. Here two small bugs.
in : find_options_for_find_tagged_with()
change : conditions << sanitize_sql(["context = ?",on.to_s])
to : conditions << sanitize_sql(["#{Tagging.table_name}.context = ?",on.to_s])in : find_options_for_tag_counts()
change:
{ :select => "#{Tag.table_name}.id, #{Tag.table_name}.name, COUNT(*) AS count",:joins => joins.join(" "), :conditions => conditions, :group => group_by }to :
{ :select => "#{Tag.table_name}.id, #{Tag.table_name}.name, COUNT(*) AS count",:joins => joins.join(" "), :conditions => conditions, :group => group_by, :order => options[:order] }Best regards,
miguel cabero
Comments
forget the first bug correction, here is the right change :
in : find_options_for_find_tagged_with()
change :unless (on = options.delete(:on)).nil?
conditions << sanitize_sql(["#{context = ?",on.to_s]) end
taggings_alias, tags_alias = "#{table_name}taggings", "#{table_name}tags"to :
taggings_alias, tags_alias = "#{table_name}taggings", "#{table_name}tags"
unless (on = options.delete(:on)).nil?
conditions << sanitize_sql(["#{taggings_alias}.context = ?",on.to_s]) end -
passed-in conditions are not being sanitized, causing some funky behavior with bound parameters; ex: :conditions => [ "foo.id IN (?)", [1,2,3,4,5] ] is being converted to SQL " foo.id in (?) AND 1 AND 2 AND 3 AND 4 AND 5"
here's a fix I applied that appears to be working:
before:
conditions = [
taggable_type, taggable_id, options[:conditions], start_at, end_at ]after:
conditions = [
taggable_type, taggable_id, sanitize_sql(options[:conditions]), start_at, end_at ]Comments
I want to add permalink attribute to tag
{ :select => "#{Tag.table_name}.id, #{Tag.table_name}.name, COUNT(*) AS count",
should be
{ :select => "#{Tag.table_name}.*, COUNT(*) AS count",
-
When I run a tag seach with :match_all => true I get the following error.
ActiveRecord::StatementInvalid (PGError: ERROR: column "entries.id" must appear in the GROUP BY clause or be used in an aggregate function : SELECT DISTINCT entries.* FROM "entries" LEFT OUTER JOIN taggings entries_taggings ON entries_taggings.taggable_id = entries.id AND entries_taggings.taggable_type = E'Entry' LEFT OUTER JOIN tags entries_tags ON entries_tags.id = entries_taggings.tag_id WHERE ((context = E'tags' AND entries_tags.name LIKE E'abandoned stairs') AND ("entries"."status" = E'published')) GROUP BY entries_taggings.taggable_id HAVING COUNT(entries_taggings.taggable_id) = 1 ORDER BY published_at DESC LIMIT 30 OFFSET 0):Comments
yep, I'm getting the same thing when deploying on Heroku (postgres) and trying to use find_tagged_with
Processing TagsController#show (for 86.130.208.17 at 2009-07-18 15:26:58) [GET]
Parameters: {"tags"=>["uk"], "action"=>"show", "controller"=>"tags"}ActiveRecord::StatementInvalid (PGError: ERROR: column "links.id" must appear in the GROUP BY clause or be used in an aggregate function
: SELECT DISTINCT links.* FROM "links" LEFT OUTER JOIN taggings links_taggings ON links_taggings.taggable_id = links.id AND links_taggings.taggable_type = E'Link' LEFT OUTER JOIN tags links_tags ON links_tags.id = links_taggings.tag_id WHERE (links_tags.name LIKE E'uk') GROUP BY links_taggings.taggable_id HAVING COUNT(links_taggings.taggable_id) = 1): /home/slugs/29705_7bbcdfd_ee70/mnt/.gems/gems/mbleigh-acts-as-taggable-on-1.0.5/lib/acts_as_taggable_on/acts_as_taggable_on.rb:117:infind_tagged_with' app/controllers/tags_controller.rb:8:inshow'It looks like it is fixed in http://github.com/harleyttd/acts-as-taggable-on/commit/a2a560191792aa0b028f751dc55ddef0da30c696
Postgres support would be welcome.
This commit resolves the problem with PostgreSQL:
http://github.com/morgoth/acts-as-taggable-on/commit/3ad83818ad3c6a5b71d6259a510ec22e8618af3c
I sent pull request.
allaboutruby
Sun Dec 06 05:23:18 -0800 2009
| link
Actually, it doesn't fix it fully. The related_search still doesn't work. To fix it you'll need to change related_search_options method :group to:
:group => "#{column_namer(klass)}",And add a new method:
def column_namer(klass) klass.column_names.map { |column| "#{klass.table_name}.#{column}" }.join(", ") endOk, so I fixed this in commit: http://github.com/morgoth/acts-as-taggable-on/commit/c8d0da01fc2faf9e09bfc14eda32d8a39ff30c14
I also sent a pull request -
Is the "acts_as_taggable_on: initialized properly" message really needed in the logs?
2 comments Created 6 months ago by dolzenkoSubject :)
Not an issue but really, I have a bunch of other plugins in my vendor folder and acts_as_taggable_on is the only one which proudly announces himself in the logs.
Comments
-
As shown below, chaining the tagged_with named scope doesn't appear to work, at least not in the way I'm doing it. What nomenclature do I used to find all Products that are tagged with both "081" and "20x24"?
Thanks.
c.>> Product.find(1).tags.map {|t| t.name} => ["081", "20x24", "aluminum", "forever", "frame"] >> Product.tagged_with("081", {}).size => 24 >> Product.tagged_with("20x24", {}).size => 94 >> Product.tagged_with("20x24, 081", {}).size => 118 >> Product.tagged_with("081", {}).tagged_with("20x24", {}).size => 0Comments
As a follow-on, I've figured out how to do what I'm after with find_tagged_with instead of the named scope. There does appear to be a bug in the tagged_with named scope implementation, though.
>> Product.tagged_with("20x24, 081", :match_all => true).size => 118 >> Product.find_tagged_with("20x24, 081", :match_all => true).size => 5Using tagged_with on more than one tag and using :match_all seems to work for me, however, I also need to chain scopes, because I want to use different contexts, for example:
User.tagged_with('technical', :on => :skills).tagged_with('funny', :on => :tags)
But that doesn't work currently... which is a shame. Like your example, it just returns an empty result set.
-
when merging conditions string parentheses should be placed around clauses with OR.
Example:currently User.tagged_with("foo, bar", :as => :languages) will result in the following query:
SELECT .... WHERE (context = 'languages' AND users_tags.name LIKE 'foo' OR users_tags.name LIKE 'bar')Note that it will improperly match 'bar' tag in any context.
Comments
-
Tags count column is missing from migration which breaks count methods
1 comment Created 3 months ago by bgilesAs pointed out by Stuart Henry https://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on/tickets/49-add-count-column-to-tags-table#ticket-49-2, the count column is not included in acts_as_taggable_on_migration. Consequently, tag counts aren't returned for User.skill_counts, etc.
To fix after the fact create a migration that includes the following:
add_column :tags, :count, :integer, :default => 0Comments
-
Hello mbleigh,
Can you move the gem to gemcutter.org?
http://gems.github.com/ doesn't work anymore :)
Thanks
Comments
I actually already did a couple weeks ago.
gem install acts-as-taggable-on --source http://gemcutter.org -
With this model code:
acts_as_taggable_on :categories
I get a model that supports self.categories. The tag context acts kind of like a has_many association. Good.
But when I add:
accepts_nested_attributes_for :categories
and POST a list of categories to the create action I get this exception deep in AR#new:
1)
ActiveRecord::AssociationTypeMismatch in 'PlacesController authenticated user should process categories parameter to create'
Tag(#2176796520) expected, got String(#2148246520)
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/association_proxy.rb:263:inraise_on_type_mismatch' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/association_collection.rb:320:inreplace' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/association_collection.rb:320:ineach' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/association_collection.rb:320:inreplace' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations.rb:1322:in `categories='It appears that the association is looking for Tag objects and won't accept the Strings I'm handing it.
Comments
Next, I tried:
accepts_nested_attributes_for :category_listBut that gave:
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/nested_attributes.rb:215:in `accepts_nested_attributes_for': No association found for name `category_list'. Has it been defined yet? (ArgumentError)You don't need to add nesting, it's built in to the model. Just add a
text_fieldforcategories_listthat accepts comma-separated values and you'll be good to go. -
Hi,
is it possible to support friendly url like in this gem http://github.com/norman/friendly_id ?
Name of the tag instead of the id in the url (and in the searching etc.)
Thanks
PetrComments
I'm not completely sure, but can't you use friendly_id and acts-as-taggable-on together? Does calling
Tag.has_friendly_id :namefrom a rails initializer work? -
tagged_with returns all results when none found
4 comments Created 17 days ago by barmstrongIs anyone else seeing this?
When I pass tagged_with a tag that does not exist, it returns every record (instead of none).
>> Website.tagged_with("some tag that does not exist", :on=>:tags).size => 239 >> Website.count => 239Comments
barmstrong
Thu Dec 17 16:03:27 -0800 2009
| link
By the way, I'm using standard latest MySQL 5.0.67, and Rails 2.3.4 so that probably isn't the issue.
Same here, with Rails 2.3.5. Seems to caused by the yesterdays optimization in 79d460e
Yeah, sorry about that. I've fixed it and released a new version.
barmstrong
Fri Dec 18 13:07:28 -0800 2009
| link
Ahh cool, thanks for the quick response!
-
Incorrectly process tag lists with two or more quotation marks.
See: http://gist.github.com/262434Comments
godfreykfc
Wed Dec 23 17:48:46 -0800 2009
| link
patched on my fork
-
It would be very nice if setting the "tag_list" attribute would support the dirty tracking available in ActiveRecord since Rails 2.1:
my_model = MyModel.create :tag_list => 'ruby' my_model.tag_list = 'ruby, rails' my_model.changed? # true my_model.tag_list_changed? # true my_model.tag_list_change # ["ruby", "ruby, rails"] my_model.changes # {"tag_list"=>["ruby", "ruby, rails"]}With such an enhancement, the plugin collectiveidea/acts_as_audited could track changes of tags.
Comments
-
tag_counts should work like find, so if I pass a condition:
Challenge.tag_counts/_on(:tags, :conditions => {:opened => false}) // or :conditions => ['challenge.opened = ?', false]just merges the strings improperly : "challenge.opened = ? false" resulting in bad query. seems to me that options.merge({.. is not needed when that can be achieved with_scope.. Will play with this today..
def tag_counts_on(context, options = {}) with_scope :find => options do Tag.find(:all, find_options_for_tag_counts(:on => context.to_s)) end endComments
-
In my app for example, top_tags doesn't recognize limits (even when trying different ways such as :limit => 3) and just lists all tags:
b = Blog.find_by_slug 'paulstamatiou-com'
b.top_tags(3)
[#<Tag id: 6, name: "software">, #<Tag id: 15, name: "Apple">, #<Tag id: 32, name: "programming">, #<Tag id: 49, name: "web">, #<Tag id: 220, name: "tech">, #<Tag id: 234, name: "Internet">, #<Tag id: 303, name: "ruby">]Comments
-
#find_related_??? does not work properly with postgresql
0 comments Created 3 months ago by tschmidtI was trying out the AATO gem and found that when I tried to use the #find_related_??? method I was getting the following error:
ActiveRecord::StatementInvalid: PGError: ERROR: column "users.name" must appear in the GROUP BY clause or be used in an aggregate function : SELECT users.*, COUNT(tags.id) AS count FROM users, tags, taggings WHERE (users.id != 1 AND users.id = taggings.taggable_id AND taggings.taggable_type = 'User' AND taggings.tag_id = tags.id AND tags.name IN (E'CSS',E'XHTML',E'HTML',E'Javascript',E'Rails',E'Ruby')) GROUP BY users.id ORDER BY count DESC
My configuration looks like this:
# == Schema Information # # Table name: users # # id :integer not null, primary key # name :string(255) # created_at :datetime # updated_at :datetime # class User < ActiveRecord::Base acts_as_taggable_on :skill end
I tracked the problem to line 280 in the lib/acts_as_taggable_on/acts_as_taggable_on.rb file. I am not sure if this is something that only happens in Postgres or if it is being seen elsewhere. I had to update the line to be
:select => "#{klass.table_name}.id, COUNT(#{Tag.table_name}.id) AS count"instead of
:select => "#{klass.table_name}.*, COUNT(#{Tag.table_name}.id) AS count"I am testing this on an iMac running 10.6.1 with Postgresql 8.3.8. Anyway, other than this minor issue I am very pleased with the gem. Thanks for the great work!
Comments
-
Option to return non-readonly records
0 comments Created about 1 month ago by tilsammansActs as taggable joins with the tags tables, and thus the records found are marked ActiveRecord::ReadOnlyRecord. An option to return writeable records is needed. If anything this caveat should be mentioned in the docs.
Comments
-
acts_as_taggable_on has_many broken in specific case
0 comments Created about 1 month ago by edwardsaI am using ActiveScaffold, and when It loads up a list of my model objects it fails on the has_many. It appears that the aliased_join_table_name is not being defaulted to "taggings". The following change fixed it locally for me:
acts_as_taggable_on.rb (line 26)
was
:include => :tag, :conditions => ['#{aliased_join_table_name rescue "taggings"}.context = ?',tag_type], :class_name => "Tagging"changed to
:include => :tag, :conditions => ['#{aliased_join_table_name || "taggings" rescue "taggings"}.context = ?',tag_type], :class_name => "Tagging"Comments
-
ArgumentError in has_many eval in Rails 2.3.4
0 comments Created about 1 month ago by simianarmyI upgraded from Rails 2.2.2 to 2.3.4 & got this error from this plugin when loading an AR class with acts_as_taggable in it:
ArgumentError ArgumentError: wrong number of arguments (2 for 1) from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations.rb:1414:in `sanitize_sql' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations.rb:1414:in `configure_dependency_for_has_many' from /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations.rb:823:in `has_many' from (eval):3:in `has_many' from RAILS_ROOT/vendor/plugins/acts-as-taggable-on/lib/acts_as_taggable_on/acts_as_taggable_on.rb:25:in `acts_as_taggable_on'I was able to fix this by downgrading to 2.3.2 - any insights?
Using this plugin version 1.0.11
Issue 17 solution did not work for me
Comments
-
tagged_with of an association returns invalid IDs
2 comments Created 6 days ago by tilsammansPage.tagged_with('see').first.id
=> 107 # correctCategory.first.pages.tagged_with('see').first.id
=> 46 # incorrect. this is the ID of the Taggable object in question.Comments
tilsammans
Mon Dec 28 01:32:28 -0800 2009
| link
using find_tagged_with('see') returns correct results in both cases, by the way.
What version of acts-as-taggable-on are you using? I'm trying to reproduce this in a local app, but I'm not having any luck.
Example:
>> City.first.companies.tagged_with('whatever').first.id => 6576 >> City.first.companies.find_tagged_with('whatever').first.id => 6576 -
error: ActiveRecord::UnknownAttributeError (unknown attribute: context):
0 comments Created 1 day ago by allyforceHi,
Starting to use acts-as-taggable-on and easing in using as if on-steroids and get a "context" error.
class Vendor...
acts_as_taggable_on :tags, :competitorsform_for @vendor |do|....
<%= f.label :tags %><br /> <%= f.text_field :tag_list %>It looks like I have added it as the model with two types of context
And then in the view new created a field for submission.
But I'm still getting an error. Thanks!
Comments






Rather, I think a better option could be:
Since this has been sitting here for 5 months without a fix, I forked it, adding the fix along with a spec:
http://github.com/skizzybiz/acts-as-taggable-on/
P.S., there are two failing specs, but they were there when I started.
This issue seems to be solved. I changed the spec to confirm this.