Looking to embed the html 'right guillemet' (») inside of a link_to reference in my view code...
<%= (role.rights.sort{|a, b| [a.controller, a.action] <=> [b.controller, b.action]}.collect{|rights| [link_to (rights.controller + " » " + rights.action, :controller => "rights", :action => "edit", :id => rights.id)]}).join("<br />").html_safe -%>
which results in...
<a href="/rights/edit/53">groups &raquo; add_member</a><br /><a href="/rights/edit/50">groups &raquo; create</a><br /><a href="/rights/edit/54">groups &raquo; delete_member</a><br /><a href="/rights/edit/52">groups &raquo; destroy</a>
which is not what I want obviously.
(and yes, I will probably just move this to a helper once I get it working)
Is it possible to embed HTML code inside the 'link_to' ?
Give an example of the html code.
I just did (» is the html I want embedded inside the 'link_to')
Craig
Looking to embed the html 'right guillemet' (») inside of a link_to reference in my view code...
<%= (role.rights.sort{|a, b| [a.controller, a.action] <=> [b.controller, b.action]}.collect{|rights| [link_to (rights.controller + " » " + rights.action, :controller => "rights", :action => "edit", :id => rights.id)]}).join("<br />").html_safe -%>
which results in...
<a href="/rights/edit/53">groups &raquo; add_member</a><br /><a href="/rights/edit/50">groups &raquo; create</a><br /><a href="/rights/edit/54">groups &raquo; delete_member</a><br /><a href="/rights/edit/52">groups &raquo; destroy</a>
which is not what I want obviously.
(and yes, I will probably just move this to a helper once I get it working)
Is it possible to embed HTML code inside the 'link_to' ?
One way is to use "#{rights.controller} » #{rights.action}".html_safe
Colin
The problem is that the “inner” string is not marked as html_safe. In your link_to tag, this string is not considered html_safe:
link_to(rights.controller + " » " + rights.action, :controller => “rights”, :action => “edit”, :id => rights.id)
Colin’s suggestion, which is the solution, is to mark the inner string as html_safe. The easiest way to do this is to use the #{} notation instead of string concatenation:
link_to(“#{rights.controller} » #{rights.action}”.html_safe , :controller
=> “rights”, :action => “edit”, :id => rights.id)