Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using link_to with block in arbre template #46

Closed
senid231 opened this issue Oct 24, 2015 · 5 comments · Fixed by #64
Closed

using link_to with block in arbre template #46

senid231 opened this issue Oct 24, 2015 · 5 comments · Fixed by #64

Comments

@senid231
Copy link

index.html.arb with such code

h1 'Dashboard#index'
para 'Find me in app/views/dashboard/index.html.arb'
link_to sign_out_path, data: {confirm: 'Are you sure?'}, method: :delete do
  i 'Logout', class: 'fa fa-lock'
end

generate incorrect html

<h1>Dashboard#index</h1>
<p>Find me in app/views/dashboard/index.html.arb</p>
<i class="fa fa-lock">Logout</i>

i can use text_node only if i use link_to without block

text_node link_to('Logout', sign_out_path, method: :delete).html_safe
<a rel="nofollow" data-method="delete" href="/sign_out">Logout</a>

i think same situation will be with any helper method with block that returns html

@timoschilling
Copy link
Member

Maybe html_node could be a solution.

@timoschilling
Copy link
Member

whats happen if you do

text_node link_to('Logout', sign_out_path, method: :delete){ i 'Logout', class: 'fa fa-lock' }.html_safe

@senid231
Copy link
Author

i think you mean

text_node link_to(sign_out_path, method: :delete){ i 'Logout', class: 'fa fa-lock' }.html_safe

it generates such html

<i class="fa fa-lock">Logout</i>
<a rel="nofollow" data-method="delete" href="/sign_out"></a>

@timoschilling timoschilling changed the title using link_to in arbre template using link_to with block in arbre template Oct 24, 2015
@seanlinsley
Copy link
Contributor

That's not really surprising, because Arbre and the Rails helper methods render HTML to different buffers.

I could see two options going forward:

  • update method_missing so that it captures any Arbre called inside the passed block into a new Arbre context, so that it doesn't get evaluated in the parent context and instead gets passed to (in this case) link_to
    • benefit: it would behave exactly like people expect it to
    • downside: it would be slower
  • update method_missing to raise an error anytime an Arbre method is called inside a block that was passed to a non-arbre method
    • benefit: it prevents users from running into surprising behavior
    • benefit: it'd definitely be faster than the other option
    • downside: it limits the flexibility that people have with Rails helper methods being used inside an Arbre template

@danielricecodes
Copy link

Fast forward to 2019. Using text_node with a Rails helper works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants