Hello,

So I have a product description field and in that product description
field every time I have the @ symbol followed by a product id the
following method will replace the @ sign with the products permalink
in a <a href=""> format.  The code below works.

  def product_description(product)
    product.description.gsub(/@(\w+)/m) do |w|
      ws = Product.find_by_id("#{$1}")
      %{<a href="#{ws.permalink}">}
    end
  end

However now I want to be able to be able to give it two options, the @
and the @c.  the @ sign will associate it with a product id and the @c
will associate it with a category id.  So I tried the following bellow
but I can only get one or the other to work, I can not get them to
work at the same time.

  def product_description(product)
    product.description.gsub(/@(\w+)/m) do |w|
      ws = Product.find_by_id("#{$1}")
      %{<a href="#{ws.permalink}">}
    end
    product.description.gsub(/@c(\w+)/m) do |w|
      ws = Category.find_by_id("#{$1}")
      %{<a href="#{ws.permalink}">}
    end
  end

If anyone has some suggestions I would greatly appreciate it.  Thanks
in advance.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to