This time, I will share as a memo for myself how to add an icon to the header that I had a hard time unexpectedly.
ruby2.6.5 Rails 6.0.3.3
bulma
You can easily display the icon by introducing font-awesome-sass and using the helper method icon. Below is the actual code.
ruby:header.html.erb
<%= link_to icon('fas','sign-in-alt', 'Login'), new_user_session_path, class: "navbar-item" %>
<%= link_to icon('fas', 'user-plus', 'sign up'), new_user_registration_path, class: "navbar-item" %>
Result ↓
Add the following to the Gemfile
Gemfile
gem 'font-awesome-saas'
Run bundle install in the terminal
Next, add the following to app / assets / stylesheets / application.scss. If you are using application.css, convert it to scss.
stylesheets/application.scss
@import 'font-awesome-sprockets';
@import 'font-awesome';
Run rails s and restart the server.
The preparation is complete! All you have to do is write the code! Isn't it really easy? I think that just having an icon will change the impression of your portfolio, so please use the icon. I would like you to add it and improve the appearance!
I hope it helps similar programming beginners.
[Rails] Thorough explanation of how to use font-awesome-sass!
Recommended Posts