[RAILS] I want to make a button with a line break with link_to [Note]

I want to make a button with a line break with link_to [Note]

When I wanted to make a button with line breaks, I was in trouble, so I will write it as a memorandum.

Wrong example

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"} %>

キャプチャ.PNG

Conclusion

<%= link_to new_user_registration_path, class: "btn btn-success" do %>
  <h2>Login</h2>
  <br>
You can comment and like by logging in!
<% end %>

キャプチャ2.PNG

Supplement

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"} %>

What is an escape character?

Special Characters To negate the effects of special characters such as \

and \
.

reference https://noterr0001.hateblo.jp/entry/20151208/1449579773

Recommended Posts

I want to make a button with a line break with link_to [Note]
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I tried to break a block with java (1)
I want to monitor a specific file with WatchService
Rails6 I want to make an array of values with a check box
I want to make a specific model of ActiveRecord ReadOnly
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to add a browsing function with ruby on rails
[Rails] I want to add data to Params when transitioning with link_to
I want to extract between character strings with a regular expression
I tried to make a group function (bulletin board) with Rails
I want to write a nice build.gradle
I want to make an ios.android app
I want to use DBViewer with Eclipse 2018-12! !!
I want to write a unit test!
I want to select multiple items with a custom layout in Dialog
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
[iOS] I tried to make a processing application like Instagram with Swift
I tried to make a Web API that connects to DB with Quarkus
[Note] I want to get in reverse order using afterLast with JdbcTemplate
I want to create a dark web SNS with Jakarta EE 8 with Java 11
I want to display a PDF in Chinese (Korean) with thin reports
If you want to make a zip file with Ruby, it's rubyzip.
I want to ForEach an array with a Lambda expression in Java
I want to test Action Cable with RSpec test
I tried to make Basic authentication with Java
java I tried to break a simple block
I did Java to make (a == 1 && a == 2 && a == 3) always true
[Ruby] I want to do a method jump!
I want to use java8 forEach with index
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I want to simply write a repeating string
I tried to create a LINE clone app
I want to design a structured exception handling
I want to play with Firestore from Rails
I made a LINE bot with Rails + heroku
Easy to make LINE BOT with Java Servlet
I want to perform aggregation processing with spring-batch
[Rails] I want to load CSS with webpacker
[LINE @] I tried to make a Japanese calendar Western calendar conversion BOT [Messaging API]
A note that I gave up trying to make a custom annotation for Lombok
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
I want to be able to read a file using refile with administrate [rails6]
I tried to make a simple game with Javafx ① "Let's find happiness game" (unfinished)
[Android] I tried to make a material list screen with ListView + Bottom Sheet
[Android] I want to make QA easier ... That's right! Let's make a debug menu!
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
[Ruby] I want to make an array from a character string with the split method. And vice versa.
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
[Ruby] I want to make a program that displays today's day of the week!
I want to go back to a specific VC by tapping the back button on the NavigationBar!
I tried to make a simple game with Javafx ① "Let's find happiness game" (unfinished version ②)
I want to call a method of another class
I read the readable code, so make a note
How to make LINE messaging function made with Ruby
Let's make a LINE Bot with Ruby + Sinatra --Part 2
I want to use a little icon in Rails
I want to dark mode with the SWT app
I want to authenticate users to Rails with Devise + OmniAuth