Embedding link_to's within text fetched from database

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.

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”) %> renders as
Visist http://example.com

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


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
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

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

You could also use an inline template


Rails mailing list
[email protected]
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

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. <

Kevin O. wrote:

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


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
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?