10000 Applying custom parser on save only · Issue #1119 · mbleigh/acts-as-taggable-on · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Applying custom parser on save only #1119
Open
@noctivityinc

Description

@noctivityinc

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0