GithubHelp home page GithubHelp logo

rocket_tag's Introduction

Rocket Tag

Clean, modern and maintainable, context aware tagging library for rails 3.1 +

Installation

In your gemfile

gem "rocket_tag"

Then at the command line

bundle install

Create the migration at the command line

rails generate rocket_tag:migration
rake db:migrate
rake db:test:prepare

Configuration

Add configurations to config/initializers/rocket_tag.rb:

RocketTag.configure do |config|
  config.force_lowercase = true # Automatically convert all tags to lowercase (optional, default: false)
end

Usage

class TaggableModel < ActiveRecord::Base
	attr_taggable :skills, :habits
end	

item = TaggableModel.create

item.skills = ["kiting", "surfing", "coding"]
item.habits = ["forking", "talking"]

Match any tag across any contexts

TaggableModel.tagged_with ["forking", "kiting"]  

Match all tags across any contexts

TaggableModel.tagged_with ["forking", "kiting"], :all => true

Match any tag on a specific context

TaggableModel.tagged_with ["math", "kiting"], :on => "skills"

Match all tags on a specific context

TaggableModel.tagged_with ["math", "kiting"], :all => true, :on => "skills"

Match a miniumum number of tags

TaggableModel.tagged_with ["math", "kiting", "coding", "sleeping"], :min => 2, :on => "skills"

Match tags to specific contexts

TaggableModel.tagged_with { :skills => ["math", "kiting"], :languages => ["english", "german"]

Take advantage of the tags_count synthetic column returned with every query

TaggableModel.tagged_with(["math", "kiting", "coding", "sleeping"], :on => "skills").where{tags_count>=2}	

Mix with active relation

TaggableModel.tagged_with(["forking", "kiting"]).where( ["created_at > ?", Time.zone.now.ago(5.hours)])  

or even downstream

User.where{email="[email protected]"}.documents.tagged_with ['kiting', 'math'] , :on => :skills

where we might have

class User < ActiveRecord::Base
  has_many :documents
end

class Document < ActiveRecord::Base
  belongs_to :user
  attr_taggable :tags
end 

Find similar models based on tags on a specific context and return in decending order of 'tags_count'

model.tagged_similar :on => "skills"
model.tagged_similar :on => "habits"

The two cases of tagged_similar below are functionally identical because there are only two contexts specified on the class. If there were three or more contexts specified then the two below would not be identical.

model.tagged_similar :on => ["skills", "habits"]
model.tagged_similar

Find popular tags and generate tags clouds for specific scopes

User.where{email="[email protected]"}.documents.popular_tags

where we might have

class User < ActiveRecord::Base
  has_many :documents
end

class Document < ActiveRecord::Base
  belongs_to :user
  attr_taggable :tags
end 

and you can access the field tags_count on each Tag instance returned by the above query. Generating the CSS and html for your tag cloud is outside the scope of this project but it should be easy to do.

Alias tags. If you have several tags that means the same things, then create alias for it.

#array with inctances of RocketTag::Tag
tag1, tag2, tag3 = ['ror', 'ruby-on-rails', 'rails'] 
tag1.alias << [tag2, tag3]
#Models with tag `rails`
# returns all Posts with `rails`, `ruby-on-rails` and `ror` tags 
Post.tagged_with(['rails']) 

Contributing to rocket_tag

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2011 Brad Phelan. See LICENSE.txt for further details.

Available for hire for your next ROR project at XTargets: Ruby On Rails Solutions

rocket_tag's People

Contributors

beanieboi avatar beans0063 avatar bradphelan avatar derekcroft avatar fntz avatar jacki3lene avatar keithpitt avatar ksoderstrom avatar manuelmeurer avatar matenia avatar mlitwiniuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rocket_tag's Issues

rails 3.2 ActiveModel::MissingAttributeError

Hi, after upgrading to rails 3.2 there is an error while trying to update attr_taggable field
ActiveModel::MissingAttributeError: can't write unknown attribute name_of_taggable_field
it points to "write_attribute(context, list)" in taggable.rb

ActiveModel::MissingAttributeError: can't write unknown attribute `elements'
from /home/grg/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/attribute_methods/write.rb:34:in `write_attribute'
from /home/grg/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/attribute_methods/dirty.rb:67:in `write_attribute'
from /home/grg/.rvm/gems/ruby-1.9.3-p0/gems/rocket_tag-0.0.4/lib/rocket_tag/taggable.rb:212:in `block (3 levels) in attr_taggable'
from (irb):5
from /home/grg/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start'
from /home/grg/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start'
from /home/grg/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

After downgrading to rails 3.1.3 everything worked fine again.

undefined local variable or method `cache_tags' after "instance methods unless required" commit

Hi, there is some strange behaviour after removing instance method.

Rails 3.2.1 ruby 1.9.3, rocket_tag 0.3.1

Before 0.3.0:
Run rails server, change some stuff in view/controller/model which addresses to any model with rocket_tag, press f5, everything is ok, continue developing.

After 0.3.0 (after commit removing inclusion instance methods by default):
Run rails server,change some stuff in view/controller/model which addresses to any model with rocket_tag, press f5, getting an error undefined local variable or method `cache_tags' for "_object_with_rocket_tags". I have to restart rails server, then everything is fine. This behaviour ruins developing process, cause restarting server every time you touch a model with tags is sad.

Tested with different commits from repo, the problem exactly begins from commit with removing instance methods.
Having not enough experience in ruby, but as I understand the problem is in reinitialising model in developer mode.

I don't say it is a bug, but it is really really unconvenient.

update:
problem is in this variable @@acts_as_rocket_tag in taggable.rb around line 230(i don't know hot to post a link to the code in github) it sets to false only with initial loading(as i understand)

Slug support

I'm using lastest rocket_tag. My app using Turkish chars so when generating new slugs based on model. Rocket tag generates tag links with special chars. How can I slugize them.

Tagger

Hello,

I just want to ask about the "tagger" stuff. Does it work yet? If so, how to use it?
Thanks in advance. I'm a rails beginner, so I'm not quite sure about what I read in the rocket_tag source code.

RocketTag.configure - undefined method configure

Added configuration option for lowercase as an initializer as such

RocketTag.configure do |config|
  config.force_lowercase = true
end

Starting the app with rails s results in error

/config/initializers/rocket_tag.rb:1:in `<top (required)>': undefined method `configure' for RocketTag:Module (NoMethodError)```

Rails 3.2.12
rocket_tag 0.5.6
Ruby 1.9.3-p194

Rocket Tag gem uninstalled, but on rake db:migrate, continues to create tables and error

Hello -

I upgraded from Rails 3.2 to Rails 4, and since RocketTag isn't yet compatible, I uninstalled it and removed the reference from my Gemfile.

However, now I'm getting errors when I run rake db:migrate:

-------- begin paste from Terminal -----------

== RocketTagMigration: migrating =============================================
-- create_table(:tags)
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::DuplicateTable: ERROR: relation "tags" already exists

-------- end paste from Terminal ---------------

I can't deploy. The "taggings" table is also created and causes same error. Even when I manually delete the tables, they come back. I have even deleted the references to these tables from my schema.rb. Where is this coming from and how can I stop it?

Thank you,
Deborah

destroy_tags_for_context generates invalid SQL statement

My model uses attr_taggable :genres

When saving I get a SQL error accessing column taggings.genres

SQL (0.7ms) DELETE FROM taggings WHERE taggings.taggable_id = 1 AND taggings.taggable_type = 'Operator' AND taggings.context = taggings.genres
(0.2ms) ROLLBACK
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'taggings.genres' in 'where clause': DELETE FROM taggings WHERE taggings.taggable_id = 1 AND taggings.taggable_type = 'Operator' AND taggings.context = taggings.genres

I'm not too familiar with squeel, but using ActiveRecord in taggings_for_context solves the issue for me:

Beans0063@f0eb7aa

Cannot save tags

Rocket_tag sometimes will not save changes to tags (or am I not adding tags the right way?).

My stack: Rails 3.2.3 running on top of Ruby 1.9.3-p125

Suggestions anyone?

irb(main):001:0> r1 = Repo.first
  Repo Load (0.3ms)  SELECT "repos".* FROM "repos" LIMIT 1
  RocketTag::Tagging Load (0.4ms)  SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_type" = 'Repo' AND "taggings"."taggable_id" IN (1)
  RocketTag::Tag Load (0.2ms)  SELECT "tags".* FROM "tags" WHERE "tags"."id" IN (2, 3, 4)
=> #<Repo id: 1, name: "foundation", owner: "zurb", description: "An easy to use, powerful, and flexible framework fo...", watchers: 3639, forks: 424, github_url: "https://github.com/zurb/foundation", homepage: "http://foundation.zurb.com", last_updated: "2012-04-21 11:45:59", created_at: "2012-04-21 12:56:54", updated_at: "2012-04-21 19:08:37", wiki_text: "Foundation is the most awesome design framework one...">
irb(main):002:0> r1.languages
=> ["kiting", "surfing"]
irb(main):003:0> r1.languages << "coding"
=> ["kiting", "surfing", "coding"]
irb(main):004:0> r1.save
   (0.1ms)  begin transaction
   (0.1ms)  commit transaction
=> true
irb(main):005:0> r2 = Repo.first
  Repo Load (0.3ms)  SELECT "repos".* FROM "repos" LIMIT 1
  RocketTag::Tagging Load (0.3ms)  SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_type" = 'Repo' AND "taggings"."taggable_id" IN (1)
  RocketTag::Tag Load (0.3ms)  SELECT "tags".* FROM "tags" WHERE "tags"."id" IN (2, 3, 4)
=> #<Repo id: 1, name: "foundation", owner: "zurb", description: "An easy to use, powerful, and flexible framework fo...", watchers: 3639, forks: 424, github_url: "https://github.com/zurb/foundation", homepage: "http://foundation.zurb.com", last_updated: "2012-04-21 11:45:59", created_at: "2012-04-21 12:56:54", updated_at: "2012-04-21 19:08:37", wiki_text: "Foundation is the most awesome design framework one...">
irb(main):006:0> r2.languages
=> ["kiting", "surfing"]
irb(main):007:0> 

Case sensitivity for tag names

Hi

Thanks for your great gem, its a breath of fresh air.

Can you give me any advice on case sensitivity for tag names, is there a way to search for tags with out case being considered.

If not what do you think about down-casing all tag names as they are saved?

Many thanks

postgresql group by issues

v0.5.1 introduces a regression in postgresql (v9.1.3 here), the group by clause does not contain the taggings.id or tags.id columns

also applies to ModelName.tagged_with

1.9.3p0 :001 > ModelName.tags
RocketTag::Tag Load (0.7ms)
SELECT "tags".*
FROM (SELECT count("tags"."id") AS tags_count, *
FROM "tags"
INNER JOIN "taggings" ON "taggings"."tag_id" = "tags"."id"
WHERE "taggings"."taggable_type" = 'ModelName'
AND "taggings"."taggable_id"
IN (SELECT "model_name"."id" FROM "model_name" )
GROUP BY "tags"."id", "tags"."name"
ORDER BY tags_count desc)
tags
PG::Error: ERROR: column "taggings.id" must appear in the GROUP BY clause or be used in an aggregate function

List all / search tags for autocomplete

Is there a way to setup a Tag#index controller to output a list of tag names (searchable) for use with an autocomplete field?

ie url for an ajax autocomplete field something like : "/tags.json", { q : "test" }

...or something like that.

I can see in the documentation how to select tags that relate (similar etc) to the original record but not for just searching all tags.

I thought it would be something like:

class TagsController < ApplicationController
  respond_to :json

  def index
    Tag.find(:all, :conditions => ['name LIKE ?', "%#{q}%"])
  end

end
match "/tags/index" => "tags#index"

but that didn't work.

Any help appreciated.

I thought about posting this on the SO but thought that if the ability isn't in the gem already then it could be discussed here and put forward here as a possible feature request.

Error when using "tagged_with" together with "includes"

I noticed an error when "tagged_with" is used together with "includes".
I added a failing test case here: krautcomputing/rocket_tag@e66410b0a9feac87a69aeb14bae90511847a3fcc

The error occurs quite deep in Active Record:

NoMethodError: undefined method `left' for :count:Symbol
# /Users/me/.rbenv/versions/1.9.3-p327-perf/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/alias_tracker.rb:64:in `block in initial_count_for'

It seems to have to do with using count in the subquery. See the full stack trace here: https://gist.github.com/4363280

SELECT "taggable_models".* FROM (SELECT count("tags"."id") AS tags_count, taggable_models.* FROM "taggable_models" INNER JOIN "taggings" ON "taggings"."taggable_id" = "taggable_models"."id" AND "taggings"."taggable_type" = 'TaggableModel' INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" WHERE "tags"."name" IN ('foo') GROUP BY "taggable_models"."id", "taggable_models"."user_id", "taggable_models"."name", "taggable_models"."type", "taggable_models"."foo" ORDER BY tags_count desc) taggable_models

I will investigate further what may cause this error but all tips are appreciated! :)

tagged_with should have option to exclude tag counts and order_by

We have to use Model.tagged_with() in a complicated sql query that is used within another sql query for the purposes of getting the MAX(table.updated_at) for a cache key. The current implementation adds complexity (and therefore processing time) to the query by always forcing

select{count(tags.id).as( tags_count)}.
select{"#{t}.*"}.
order("tags_count desc")

This also creates a MySQL error (duplicate column) when paired with .select("table_name.updated_at"). So that Model.select('table_name.updated_at').tagged_with(['my','tags']) fails.

I'm forking this project and will attempt a patch and pull request.

Match exact tags

I just found this library after getting annoyed at the amount of bugs and lack of support in acts-as-taggable-on. It looks really great and I'd love to just jump in and switch.

One thing I desperately need is to match tags exactly and I'm not sure it's possible with rocket_tag.
To clarify:

class TaggableModel < ActiveRecord::Base
  attr_taggable :skills
end 

item1 = TaggableModel.create(skills: ["kiting", "surfing"])
item2 = TaggableModel.create(skills: ["kiting", "surfing", "coding"])

# Now I need to be able to find items that have exactly these skills: ["kiting", "surfing"]
# Which would be only item1

# This doesn't work:
TaggableModel.tagged_with ["kiting", "surfing"]
#=> [item1, item2]

# Neither does this:
TaggableModel.tagged_with ["kiting", "surfing"], all: true
#=> [item1, item2]

# I need something like this:
TaggableModel.tagged_with ["kiting", "surfing"], exact: true
#=> [item1]

Does anyone else need this functionality or is it just me?

How hard would it be to add this?
I'm happy to submit a pull request but I had a look at RocketTag::Taggable::ClassMethods.tagged_with and couldn't immediately see how to implement it.

Any pointers would be welcome! ๐Ÿ˜„

Getting SQL error with popular_tags on model

Trying this in Console, I get a big long error related to SQL:

1.9.2p320 :001 > Page.popular_tags
  RocketTag::Tag Load (0.3ms)  SELECT `tags`.* FROM (SELECT count(`tags`.`id`) AS tags_count, * FROM `tags` INNER JOIN `taggings` ON `taggings`.`tag_id` = `tags`.`id` WHERE `taggings`.`taggable_type` = 'Page' AND `taggings`.`taggable_id` IN (SELECT `pages`.`id` FROM `pages` ) GROUP BY `tags`.`id`, `tags`.`name`, taggings.id, tags.id ORDER BY tags_count desc) tags 
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM `tags` INNER JOIN `taggings` ON `taggings`.`tag_id` = `tags`.`id` WHERE `' at line 1: SELECT `tags`.* FROM (SELECT count(`tags`.`id`) AS tags_count, * FROM `tags` INNER JOIN `taggings` ON `taggings`.`tag_id` = `tags`.`id` WHERE `taggings`.`taggable_type` = 'Page' AND `taggings`.`taggable_id` IN (SELECT `pages`.`id` FROM `pages` ) GROUP BY `tags`.`id`, `tags`.`name`, taggings.id, tags.id ORDER BY tags_count desc) tags 
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `block in execute'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:215:in `exec_query'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:224:in `select'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/querying.rb:38:in `block in find_by_sql'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/explain.rb:40:in `logging_query_plan'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/querying.rb:37:in `find_by_sql'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/relation.rb:171:in `exec_queries'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/relation.rb:160:in `block in to_a'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/explain.rb:33:in `logging_query_plan'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/relation.rb:159:in `to_a'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.6/lib/active_record/relation.rb:498:in `inspect'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
    from /Users/waltd/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'

I've stared at it for a while, and I can't see what's wrong here. I'd just like to get a list of the currently used tags, in order of usage.

Thanks,

Walter

Rocket_tag won't install in Rails 4.0.0.beta

Dependencies prevent installation in a Rails 4 (beta) application with the following bundler errors:

Fetching gem metadata from https://rubygems.org/......
Bundler could not find compatible versions for gem "activerecord":
In Gemfile:
rocket_tag (>= 0) ruby depends on
activerecord (~> 3.1.0.alpha) ruby

rails (>= 0) ruby depends on
  activerecord (4.0.0.beta)

Is there anyway to enable Eager Loading on tags?

Hi, at the moment whenever retrieving a list of taggable elements, there are queries run for retrieving tags against each element I was wondering if this could be controlled i.e only load all tags when required or directly referred to?

syntax error after installing rocket_tag gem

Platform: ruby 1.8.7 on mac osx lion, rails 3.2.1, rocket_tag installed as a gem
When I try to run rails server (or rails generate rocket_tag:migration), I get a syntax error as follows:

/Library/Ruby/Gems/1.8/gems/rocket_tag-0.3.1/lib/rocket_tag/taggable.rb:157: syntax error, unexpected '.', expecting kEND (SyntaxError)
.select("#{self.table_name}.*").
^

popular_tags on relation

Calling popular_tags on a model class works flawless, but it seems not possible to call it on a relation or scope.
My model is called business and has (rocket)tags. If I do something like

@businesses = Business.near(lat,lng)

And then call

@businesses.popular_tags

to get the tag_cloud for this subset of entities, i get the following exception:

PGError: ERROR:  subquery has too many columns
LINE 1: ...e_type" = 'Business' AND "taggings"."taggable_id" IN (SELECT...
                                                             ^
: SELECT COUNT(*) FROM (SELECT count("tags"."id") AS tags_count, tags.* FROM "tags" INNER JOIN "taggings" ON "taggings"."tag_id" = "tags"."id" WHERE "taggings"."taggable_type" = 'Business' AND "taggings"."taggable_id" IN (SELECT  businesses.*, 6371.0 * 2 * ASIN(SQRT(POWER(SIN((52.5408134 - businesses.latitude) * PI() / 180 / 2), 2) + COS(52.5408134 * PI() / 180) * COS(businesses.latitude * PI() / 180) * POWER(SIN((13.4155842 - businesses.longitude) * PI() / 180 / 2), 2) )) AS distance, CAST(DEGREES(ATAN2( RADIANS(businesses.longitude - 13.4155842), RADIANS(businesses.latitude - 52.5408134))) + 360 AS decimal) % 360 AS bearing, "businesses"."id" FROM "businesses"  WHERE (6371.0 * 2 * ASIN(SQRT(POWER(SIN((52.5408134 - businesses.latitude) * PI() / 180 / 2), 2) + COS(52.5408134 * PI() / 180) * COS(businesses.latitude * PI() / 180) * POWER(SIN((13.4155842 - businesses.longitude) * PI() / 180 / 2), 2) )) <= 50) ORDER BY distance LIMIT 9 OFFSET 0) GROUP BY "tags"."id", "tags"."name" ORDER BY tags_count desc) tags

The SQL is not correct, because a IN may not have more than one selected attribute. I don't know though how to rewrite the query correctly in the mind of rocket_tag. Any idea? Is this a error at all or am I using rocket_tags incorrectly. There has to be a way to achieve tag_cloud for subsets.

model.find_similar not found

What am I doing wrong?

ruby-1.9.2-p290 :078 > b.hardware
 => ["ff", "dfg"] 
ruby-1.9.2-p290 :079 > b.class
 => Event(id: integer, name: string, description: text, created_at: datetime, updated_at: datetime) 
ruby-1.9.2-p290 :080 > b.hardware
 => ["ff", "dfg"] 
ruby-1.9.2-p290 :081 > b.find_similar
NoMethodError: undefined method `find_similar' for #<Event:0x8982774>
    from /home/russell/.rvm/gems/ruby-1.9.2-p290/gems/activemodel-3.1.3/lib/active_model/attribute_methods.rb:385:in `method_missing'
    from /home/russell/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/attribute_methods.rb:60:in `method_missing'
    from (irb):81
    from /home/russell/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
    from /home/russell/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
    from /home/russell/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

conflict with action_view tag_helper in resque

I have rails 3.2.8, rocket_tag 0.5.6, and tried squeel (1.0.5, 1.0.9, 1.0.11 and 1.0.13) but I keep getting:

/app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/helpers/tag_helper.rb:65:in `tag'
/app/vendor/bundle/ruby/1.9.1/gems/rocket_tag-0.5.6/lib/rocket_tag/taggable.rb:183:in `block in tagged_with'
/app/vendor/bundle/ruby/1.9.1/gems/squeel-1.0.5/lib/squeel/dsl.rb:31:in `instance_eval'
/app/vendor/bundle/ruby/1.9.1/gems/squeel-1.0.5/lib/squeel/dsl.rb:31:in `eval'
/app/vendor/bundle/ruby/1.9.1/gems/squeel-1.0.5/lib/squeel/adapters/active_record/3.1/relation_extensions.rb:250:in `joins'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/querying.rb:9:in `joins'
/app/vendor/bundle/ruby/1.9.1/gems/rocket_tag-0.5.6/lib/rocket_tag/taggable.rb:183:in `tagged_with'

I even tried pull by @Fntzr. Seems like the line

joins{taggings.tag}

resolves tag to the action_view tag helper method which is totally unrelated. This happens only in resque tasks. Any help is greatly appreciated.

Tag array being output in text field

I've updated to rails 3.2.8 and latest postgres so that I can use the rocket_tag gem which sounds great.

I've added :tags to the attr_accessible list in my model.

I've added attr_taggable :tags to my model as well.

If I type a comma seperated list of tags in my f.text_field :tags then it saves them ok but if I try to edit the record that I've just created the tags field displays the tags like this: ["test1", "test2"].

Have I missed someting obvious and crucial?

Am I supposed to join the tags together myself in the text field or should the gem be doing that?

Is that so that I can join them with just a comma in the text field but as individual span elements or something on the frontend so that they can be styled individually?

If so can you offer any guidance on what the code for each of these might look like?

Thanks

tagger?

I couldn't find any use of tagger in the source code, readme or specs..
What's the best way to set it and use it while creating a tag or in the models so it is handled automatically?

Thanks

Tags and Taggings preload

Hi,

Thanks for the gem, it's awesome !
Sorry in advance if I'm opening an issue on a topic that already has been addressed.

I'm questionning about the goal of these lines in https://github.com/bradphelan/rocket_tag/blob/master/lib/rocket_tag/taggable.rb:

            default_scope do
              preload{taggings}.preload{tags}
            end

I can imagine why tags are being preloaded but in my case it causes performance issues as it loads the taggings for every user all the time, even though I don't need them in some listings of my app.

I've tried removing these lines and it improves performances on my side and it still loads tags when they are needed.

Does someone have thoughts about that?

Cache_tags - error using rails with solr, foreman, unicorn and tag-it jquery-plugin

First of all, I've already checked the issues related with this one that I am reporting.

I've created a demo app so you can clone and try to reproduce the bug.
https://github.com/sauron/test-rocket-tag-solr-foreman

The weird thing is that I am using rails 3.2.3 with solr foreman unicorn and the tag-it plugin.
Apparently if the tag attribute is not present in the form, it raises the exception, but, after a few test, realize that everytime that the model change, it fails with the exception
undefined local variable or method `cache_tags' for #<Product:...
Hope it helps, it took me a while try to resolve this, but I coudn't.

So, I hope you can help me whit this.
Thanks.

TaggableModel.tagged_with doesn't work with PostgreSQL

The problem is that when you use an aggregate function in a query, postgres strictly requires that all other columns should be listed in the GROUP BY clause. So, supposing my model is User, with an id, name and attr_taggable :roles, and I attempt to execute User.tagged_with ['admin'], the resulting query will be:

SELECT * FROM (
  SELECT count(users.id) AS tags_count, users.*
    FROM users INNER JOIN taggings
      ON taggings.taggable_id = users.id
      AND taggings.taggable_type = 'User'
    INNER JOIN tags
      ON tags.id = taggings.tag_id
    WHERE tags.name IN ('admin')
    GROUP BY users.id
) users

Postgres will complain:

ERROR: column "users.name" must appear in the GROUP BY clause or be used in an aggregate function

This is a problem for me because Heroku is backed by postgres. A synonymous query that postgres accepts is:

SELECT * FROM users WHERE id IN (
  SELECT taggable_id
    FROM taggings INNER JOIN tags
      ON tags.id = taggings.tag_id
    WHERE tags.name IN ('admin')
      AND taggings.taggable_type = 'User'
)

Or, to get the functionality of the :all => true option:

SELECT * FROM users WHERE 2 = (
  SELECT count(*)
    FROM taggings INNER JOIN tags
      ON tags.id = taggings.tag_id
    WHERE tags.name IN ('admin','sales')
      AND taggings.taggable_id=users.id
      AND taggings.taggable_type = 'User'
)

And of course a similar query can be used for :min => n. These queries also work with SQLite3, I'm not sure about other db engines but I think it's all standard SQL syntax.

I don't really know how to convert this into query builder syntax but I will give it a shot when I get time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.