When I wanted to make a button with line breaks, I was in trouble, so I will write it as a memorandum.
If you enter \ to start a new line in <% =%>, it will be output as it is.
<%= link_to "<h2>Login</h2></br>Loginすると、コメント・いいねが可能です!",new_user_registration_path, {class: "btn btn-success"} %>
<%= link_to new_user_registration_path, class: "btn btn-success" do %>
<h2>Login</h2>
<br>
You can comment and like by logging in!
<% end %>
When I first posted, I was using the raw method, From @jnchito, "If you use the raw method inadvertently, it will cause XSS to be built in, so it is better not to use it as much as possible. Rails should have various ways to build HTML without using raw, so first look for a way that doesn't rely on raw. I will correct it after receiving a comment.
Unwanted example escaped using raw method
<%= link_to raw("<h2>Login</h2></br>Loginすると、コメント・いいねが可能です!"),new_user_registration_path, {class: "btn btn-success"} %>
Special Characters To negate the effects of special characters such as \
and \
.
reference https://noterr0001.hateblo.jp/entry/20151208/1449579773
Recommended Posts