Monster on Fire

Configuring act_as_taggable_on gem to use commas with Rails 4.2.5

10 December 2016

Last week I worked on an issue where I had to add category tags to a particular model in our backend. While attempting a manual implementation, I found there was a gem that did this.


When it came to configuring the delimiter characters, the README on the repository wasn't very clear.

With the default implementation of the gem, the behaviour is as follows:

  • Add tags in input field and save
  • When you attempt to edit tags, all commas used to separate the tags have been stripped

This behaviour is apparently by design.


Configure acts_as_taggable_on to use both spaces and commas to separate tags. And make sure commas are not stripped when editing.


Following the gem's README:

# Gemfile
gem 'acts-as-taggable-on'

and in the terminal, bundle:

bundle install

run migrations

rake acts_as_taggable_on_engine:install:migrations
rake db:migrate
Model integration
class Trip
Controller integration

Add :tag_list to the whitelist

def create
  @trip = Trip.create(trip_params)
  redirect_to @trip


def trip_params
Add resource to routes
# config/routes.rb
resources :tags, only:[:index, :show]
Configuring delimiters

Add the delimiters to the Application_controller

ActsAsTaggableOn.delimiter=[',',' ']

Then in the form, the syntax for the input should be:

= f.input :tag_list, label: "Tags", input_html: { value: @trip.tag_list.to_s }
h2 Tags
= render @trip.tags
Helpful Links:

That is all.

© 2020 -