Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
fix README: add parse:true documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
billychan committed Dec 28, 2013
1 parent 3f72ee2 commit f27f945
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ If you want, add a `.ruby-version` file in the project root (and use rbenv or RV

## Usage

*Note: The following examples with delimiters inside string argument all
depend on `ActsAsTaggableOn.delimiter` being set to ',' which is the
default. See [configuration](#configuration) for more about delimiter.*

```ruby
class User < ActiveRecord::Base
# Alias for acts_as_taggable_on :tags
Expand All @@ -73,19 +77,42 @@ class User < ActiveRecord::Base
end

@user = User.new(:name => "Bobby")
@user.tag_list = "awesome, slick, hefty" # this should be familiar
@user.skill_list = "joking, clowning, boxing" # but you can do it for any context!

@user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
@user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
@user.skill_list # => ["joking","clowning","boxing"] as TagList
# this should be familiar
@user.tag_list = "awesome, slick, hefty"

# but you can do it for any context!
@user.skill_list = "joking, clowning, boxing"

@user.tags
# => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]

@user.skills
# => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]

@user.skill_list
# => ["joking","clowning","boxing"] as TagList

# remove a single tag
@user.tag_list.remove("awesome")

# "remove" works with arrays too
@user.tag_list.remove("awesome", "slick")

# "remove" works with string too, needing "parse: true" option.
@user.tag_list.remove("awesome, slick", parse: true)

# add a single tag. alias for <<
@user.tag_list.add("awesomer")

# "add" also works with arrays
@user.tag_list.add("awesomer", "slicker")

@user.tag_list.remove("awesome") # remove a single tag
@user.tag_list.remove("awesome, slick") # works with arrays too
@user.tag_list.add("awesomer") # add a single tag. alias for <<
@user.tag_list.add("awesomer, slicker") # also works with arrays
# "add" works with string too, needing "parse: true" option.
@user.tag_list.add("awesomer, slicker", parse: true)

User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
User.skill_counts
# => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
```

To preserve the order in which tags are created use `acts_as_ordered_taggable`:
Expand Down

0 comments on commit f27f945

Please sign in to comment.