rubyonrailsin

A Ruby and Rails talk

Friday, March 12, 2010


[Rails] Create links with gsub

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Hello,

So I have a text area that displays a products description, in the
products description I would like to be able to create links to other
products through the product's id. Mainly because the url's will
change from time to time and I would hate to have random broken links
on my site. Anyways so far I have this in my helper.

module ProductsHelper
def product_description(product)
product.description.gsub(/<a='''>/, "<a href='test.com'>")
end

and then in my view I have this;

<%= product_description(@product) %>

Now when editing the text area for the products description, I would
like to do something like this;

This is a test <a=12345>Product x</a>

So I would like gsub to be able to get the product id which would be
12345 and then replace that product id with the product.permalink
field that is associated with that product.id. as you can tell I am
totally lost on where to even go from here. any help would be greatly
appreciated. 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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive