arbre icon indicating copy to clipboard operation
arbre copied to clipboard

Nested link generation

Open kvokka opened this issue 9 years ago • 4 comments

Hello I try to do something like

                user_with_link = link_to(user.email, [:admin, user])
                h3 [user_with_link,  v.event,  l(v.created_at, format: :short)].join(', ')

and fails, becourse of geting "safe" first tag output and link writes in compile html like <a href="/admin/admin_users/1">[email protected]</a>, create, 29 feb., 00:46

As you understand, i just want to have h3 tag, where part of it will be link.

I try out code like raw( "<h3>" + [user_with_link, v.event, l(v.created_at, format: :short)].join(', ') + "</h3>") but it was not good also.

h3 tad does not accept the block, so, i can not push sew different lines of code.

I tryed out to use text_node, but it also escape the output, outerway i loose the context.

How I can provide propper output in Arbre way?

Thank you

kvokka avatar Feb 29 '16 01:02 kvokka

This works for me:

include ActionView::Helpers::UrlHelper

Arbre::Context.new{
  h3 link_to('foo', 'bar') + ', something, else'
}
 => <h3><a href="bar">foo</a>, something, else</h3>

seanlinsley avatar Feb 29 '16 03:02 seanlinsley

Thank you for your answer, but is no good also I need to mansion, that I use Arbre gem as the part of ActiveAdmin, and I just want to customize some view in right way

so, I need not include UrlHelper

this is pry output

[1] pry(#<ActiveAdmin::Views::Pages::Show>)> h3 [user_with_link, v.event, I18n.l(v.created_at, format: :short)].join(", ")
=>               <h3>&lt;a href=&quot;/admin/admin_users/1&quot;&gt;[email protected]&lt;/a&gt;, update, 29 февр., 02:06</h3>

[2] pry(#<ActiveAdmin::Views::Pages::Show>)> Arbre::Context.new{
[2] pry(#<ActiveAdmin::Views::Pages::Show>)*   h3 [user_with_link, v.event, I18n.l(v.created_at, format: :short)].join(", ")                  
[2] pry(#<ActiveAdmin::Views::Pages::Show>)* }                  
=> <h3>&lt;a href=&quot;/admin/admin_users/1&quot;&gt;[email protected]&lt;/a&gt;, update, 29 февр., 02:06</h3>

[3] pry(#<ActiveAdmin::Views::Pages::Show>)> 

As you can see it is the same output

kvokka avatar Feb 29 '16 03:02 kvokka

Try using the syntax that @seanlinsley used, rather than wrapping your parameters in an array.

I tried the following and it rendered fine:

ActiveAdmin.register_page "Test" do
  content do
    h3 link_to(AdminUser.find(1).email, admin_admin_user_url(1)) + ', more text'
  end
end

Rendered html:

<h3><a href="/admin/admin_users/1">[email protected]</a>, more text</h3>

OscarBarrett avatar Feb 29 '16 06:02 OscarBarrett

It is better to make it in ApplicationController

class ApplicationController < ActionController::Base include ActionView::Helpers::UrlHelper end

thucnh avatar May 31 '19 17:05 thucnh