# Embedding link\_to's within text fetched from database

**URL:** <https://www.ruby-forum.com/t/embedding-link-tos-within-text-fetched-from-database/62412>\
**Category:** Rails\
**Created:** [June 4, 2006, 11:47am UTC](https://www.ruby-forum.com/t/embedding-link-tos-within-text-fetched-from-database/62412 "2006-06-04T11:47:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [June 4, 2006, 11:47am UTC](https://www.ruby-forum.com/t/embedding-link-tos-within-text-fetched-from-database/62412/1 "2006-06-04T11:47:26Z")

</div>

Hi,

I have the following problem that I can’t seem to figure out. I want to  
able to fetch some text from my database record in my controller, and  
then  
add two links within the text and then send that back to the view to get  
rendered so that the two links appear as links and when clicked on,  
they’d  
basically call the corresponding action for the link. Would anybody  
know  
how to go about doing this? How do you get a view to render the link  
out?

Thanks and any help appreciated.

---

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [June 4, 2006, 12:44pm UTC](https://www.ruby-forum.com/t/embedding-link-tos-within-text-fetched-from-database/62412/2 "2006-06-04T12:44:14Z")

</div>

In your controller, you just take the @text from the database, copy it  
to a new member variable @text\_with\_links, add a new link “by hand” to  
that variable (@text\_with\_links += 'link") and last render @text\_with\_links instead of @text  
at your view.

If the link was not to an action, you could use auto\_link in your view.  
\<%= auto\_link(“Visit [http://example.com](http://example.com)”) %\> renders as  
Visist [http://example.com](http://example.com)

---

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [June 4, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/embedding-link-tos-within-text-fetched-from-database/62412/3 "2006-06-04T14:13:03Z")

</div>

On Sunday, June 04, 2006, at 12:44 PM, mh789 wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

You could also use an inline template

render :inline=\>“\<%= @text\_from\_database %\> \<%= link\_to ‘link’,  
:action=\>‘action’ %\>”’

\_Kevin

---

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [June 4, 2006, 2:37pm UTC](https://www.ruby-forum.com/t/embedding-link-tos-within-text-fetched-from-database/62412/4 "2006-06-04T14:37:44Z")

</div>

On Sunday, June 04, 2006, at 2:22 PM, Guest wrote:

> > You could also use an inline template
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Doing this in a view would be trivial, doing it in a model would  
probably be a bad idea.  
What exactly did you have in mind?

\_Kevin

---

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [June 5, 2006, 10:07am UTC](https://www.ruby-forum.com/t/embedding-link-tos-within-text-fetched-from-database/62412/5 "2006-06-05T10:07:14Z")

</div>

The problem is, if adding the links is dynamically determined, then in  
your  
view, you’d need some way to know that some particular database fetched  
text  
needs links while others don’t. If you do it in the controller, then  
your  
logic just goes there and you just embed the links when need be.

thanks.

On 4 Jun 2006 12:34:26 -0000, Kevin O. \<

---

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [June 4, 2006, 2:22pm UTC](https://www.ruby-forum.com/t/embedding-link-tos-within-text-fetched-from-database/62412/6 "2006-06-04T14:22:50Z")

</div>

Kevin O. wrote:

> On Sunday, June 04, 2006, at 12:44 PM, mh789 wrote:
> 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> You could also use an inline template
> 
> render :inline=\>“\<%= @text\_from\_database %\> \<%= link\_to ‘link’,  
> :action=\>‘action’ %\>”’
> 
> \_Kevin

Is there any way to do this outside of a controller?
