Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying custom parser on save only #1119

Open
noctivityinc opened this issue Dec 7, 2023 · 0 comments
Open

Applying custom parser on save only #1119

noctivityinc opened this issue Dec 7, 2023 · 0 comments

Comments

@noctivityinc
Copy link

I created a custom parser to remove the # sign from the start of any tags that a user enters in:

class NoHashTagsParser < ActsAsTaggableOn::GenericParser
  def parse
    ActsAsTaggableOn::TagList.new.tap do |tag_list|
      tag_list.add @tag_list.split(',').inject([]) {|res, tag| res << (tag.starts_with?('#') ? tag[1..-1] : tag)}
    end
  end
end

ActsAsTaggableOn.force_lowercase = true
ActsAsTaggableOn.default_parser = NoHashTagsParser

So if they enter in "this,#is,a,#test" it will save it, correctly, as [this,is,a,test]. that works fine. However the parser seems to get called every time I want to loop through the tags as well, which results in an error like this:

undefined method `starts_with?' for ["testing"]:Array

how can I have a custom parser that works on save only?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant