Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8776721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:07:22+00:00 2026-06-13T19:07:22+00:00

Hi I am working on a Rails 3 project and I am using acts-as-taggable-on

  • 0

Hi I am working on a Rails 3 project and I am using acts-as-taggable-on and everything works perfectly! 🙂

I just have one question.

Does anyone know how I can add my ‘custom’ validation to ActsAsTaggableOn::Tag? Any callbacks I can hook into (e.g before_tag_save)? or something similar?

I need to run a regex on each ‘tag’ (to ensure that each tag does not contain any illegal characters) in my tag_list before I save my model and would like to know if there is a standard way of doing it.

The way I solved the problem is by adding a validation method in my PostController which just iterates over the list of Tags and runs the regex, but this seems ugly to me.

Any suggestions?

Thank you in advance! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:07:24+00:00Added an answer on June 13, 2026 at 7:07 pm

    I used two ways in the past. One via a custom validator, another with a validates call.

    Custom Validation method

    In your model, setup the following

      validate :validate_tag
    
      def validate_tag
        tag_list.each do |tag|
          # This will only accept two character alphanumeric entry such as A1, B2, C3. The alpha character has to precede the numeric.
          errors.add(:tag_list, "Please enter the code in the right format") unless tag =~ /^[A-Z][0-9]$/
        end
      end
    

    Obviously you will need to replace the validation logic and the error message text with something more appropriate in your circumstance.

    Keep in mind that in this scenario you can evaluate each tag as a string.

    Standard Validation Method

    Include this in your model

    validates :tag_list, :format => { :with => /^([A-Z][0-9],?\s?)*$/,
          :message => "Just too awesomezz" }
    

    With this method, you will have to keep in mind that you are validating the entire array that looks like a string. For this reason, you will need to allow for commas and white spaces between the tags.

    Choose whichever method suits you most

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on rails project, which had been made using noSql(Mongoid). Every
I'm using the will_paginate gem for my Rails project and it's working beautifully. Unfortunately,
im working in a project writen in ruby on rails and im currently using
Hi Currently i am working on a rails project . where i have to
I am working on Ruby on Rails. A project which works fine on local
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
I am working on a rails project using svn. I generated a migration file
I am working on ruby rails project. I am using Rails 2.3.4 and ruby
I am working in a Mobile project (using Titanium Studio), in which i have
I have been working on Ruby on rails project for a while now, when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.