Sam Donaldson
2006-Jun-04 09:45 UTC
[Rails] 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060604/03f3a7aa/attachment.html
mh789
2006-Jun-04 10:44 UTC
[Rails] Re: Embedding link_to''s within text fetched from database.
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 += ''<a href="'' + url_for(action => ''...'') + ''">link</a>") 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 <a href="http://example.com">http://example.com</a> -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich
2006-Jun-04 12:12 UTC
[Rails] Re: Embedding link_to''s within text fetched from database.
On Sunday, June 04, 2006, at 12:44 PM, mh789 wrote:>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 += ''<a href="'' + url_for(action => >''...'') + ''">link</a>") 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 <a href="http://example.com">http://example.com</a> > > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsYou could also use an inline template render :inline=>"<%= @text_from_database %> <%= link_to ''link'', :action=>''action'' %>"'' _Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
Guest
2006-Jun-04 12:23 UTC
[Rails] Re: Embedding link_to''s within text fetched from database.
Kevin Olbrich wrote:> On Sunday, June 04, 2006, at 12:44 PM, mh789 wrote: >> >>-- >>Posted via http://www.ruby-forum.com/. >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails > > You could also use an inline template > > render :inline=>"<%= @text_from_database %> <%= link_to ''link'', > :action=>''action'' %>"'' > > _KevinIs there any way to do this outside of a controller? -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich
2006-Jun-04 12:34 UTC
[Rails] Re: Embedding link_to''s within text fetched from database.
On Sunday, June 04, 2006, at 2:22 PM, Guest wrote:>Kevin Olbrich wrote: >> On Sunday, June 04, 2006, at 12:44 PM, mh789 wrote: >>> >>>-- >>>Posted via http://www.ruby-forum.com/. >>>_______________________________________________ >>>Rails mailing list >>>Rails@lists.rubyonrails.org >>>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? > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsDoing 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 -- Posted with http://DevLists.com. Sign up and save your mailbox.
Sam Donaldson
2006-Jun-05 08:04 UTC
[Rails] Re: Embedding link_to''s within text fetched from database.
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 Olbrich < devlists-rubyonrails@devlists.com> wrote:> > > On Sunday, June 04, 2006, at 2:22 PM, Guest wrote: > >Kevin Olbrich wrote: > >> On Sunday, June 04, 2006, at 12:44 PM, mh789 wrote: > >>> > >>>-- > >>>Posted via http://www.ruby-forum.com/. > >>>_______________________________________________ > >>>Rails mailing list > >>>Rails@lists.rubyonrails.org > >>>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? > > > >-- > >Posted via http://www.ruby-forum.com/. > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >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 > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060605/af2c0b38/attachment.html