Forum: Ruby on Rails Allowing only one tag per post

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
aa b. (Guest)
on 2009-05-05 20:33
I'm using acts_as_taggable_on_steroids to add a tag to a post. For my
purposes, I only want to allow one tag per post. I've looked through the
acts_as_taggable_on_steroids code and can't really put a finger on where
I should even start. I guess I could do this in a number of ways. I
could modify input on the tag_list form (of the post create action) or
edit the plugin directly. I think modifying the input from the form
would be best, but I'm not sure. It might be easier to modify
acts_as_taggable_on_steroids instead.
So basically if the input has a comma in it it separates the string into
two tags. So I somehow need to get it to ignore the commas. Does anyone
know how I should go about this? Any advice or code would be greatly
appreciated. Thanks in advance.
aa b. (Guest)
on 2009-05-06 20:31
I found this code in another post:
  # clean string to remove spaces and force lowercase
  def self.clean_string(string)
    (string.downcase).gsub(" ","")
My form:
  <% form_for @post, :html => { :multipart => true } do |f| %>
    <%= f.label 'Topic' %><br />
    <%= f.text_field :tag_list %>
  <% end %>
I could use something like this in a callback to remove commas from the
input on the text_field correct?
This topic is locked and can not be replied to.