Last active
May 13, 2023 15:00
-
-
Save zulhfreelancer/ca6ef3fbb41ac235b231adecb33e495f to your computer and use it in GitHub Desktop.
How to add link inside Rails flash message? Tested with Rails 6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
* File: app/views/shared/_flash.html.erb | |
* Note: the `html_safe` is important here | |
--> | |
<% flash.each do |type, msg| %> | |
<div class="alert alert-info"> | |
<%= msg.html_safe %> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
File: app/views/layouts/application.html.erb | |
--> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Your App</title> | |
<meta name="viewport" content="width=device-width,initial-scale=1"> | |
<%= csrf_meta_tags %> | |
<%= csp_meta_tag %> | |
<%= stylesheet_link_tag 'application', media: 'all' %> | |
<%= javascript_pack_tag 'application' %> | |
</head> | |
<body> | |
<%= render "shared/flash" %> | |
<%= yield %> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourController < ApplicationController | |
def your_method | |
# Other logic here | |
# Note that we are using "view_context" here | |
flash[:error] = "Click #{view_context.link_to 'here', something_path} to learn more" | |
redirect_to other_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment