Well, I finally figured it out, might as well post it just in case
anyone else is trying to do the same thing. Below is the code.
# converts @ signs into product links and category links
def product_description(product)
product.description.gsub(/@(\w+)/m) do |w|
if #{$1} =~ /p(.*)/
wp = Product.find_by_id("#{$1}".delete "p")
%{<a href="#{wp.permalink}">}
else
wt = Taxon.find_by_id("#{$1}".delete "t")
%{<a href="/t/#{wt.permalink.chop}">}
end
end
end
Pretty much what this allows me to do is I can take a text field and
automatically add links to words for example;
this is a test, this is a link to a @p30 product</a>, and this is a
link to a @t45 category</a>
That way it makes my admin views a little bit cleaner and eventually I
will add a rescue feature so if that product or category has been
deleted i wont have any broken links through out the site.
--
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.