I have an issue in a specific page of the app, that is fixed when turbolink is disabled. I know that adding data-no-turbolink
as a body attribute fixes that, but I don't want turbolink to be disabled everywhere.
So, the best solution is to use something like content_for
in the specific view that has the issue (I'm using HAML):
- content_for :body, "data-no-turbolink"
But it doesn't work (the page load with the content, no error but there is no data-no-turbolink
in the body tag, and the issue is still live.)
I also tried this, with no success:
application.html.haml:
%body{ yield(:body_attr) if content_for?(:body_attr) }
my_view.html.haml:
- content_for :body_attr, "data-no-turbolink"
How can I add an attribute to <body>
from a view? Thanks.
A little late to solve htaidirt issue, but for anyone else struggling I've just had and solved this issue with the following.
Layout
%body{ no_turbolink? }
Helper
def no_turbolink?
if content_for(:no_turbolink)
{ data: {no_turbolink: true} }
else
{ data: nil }
end
end
View
content_for :no_turbolink, true
Hope this helps, Chris.
<%= content_for :body_attr, data: { no_turbolink: true } %>
. Or try adding this attribute to the outer block.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.