[Rails] Get the path name of the URL before the transition and change the link destination

environment

rails 6.0.3

Explanation

How to branch the link destination to be displayed on the page according to the ** path name ** in ʻURL` of the page before the transition.

Supplement

Applicable view file


<% if URI(request.referer.to_s).path == 'Path name' %>
  #Link destination when the previous page is the specified path
<% else %>
  #Other links
<% end %>
  1. request.referer returns a string.
  1. You can only request the path by wrapping request.referer using Ruby's ʻURI module``.

Reference article

How to get all URLs and branch the link to be displayed on the page https://qiita.com/taka_571/items/9b1c82d8fcc602df8a1a

Recommended Posts

[Rails] Get the path name of the URL before the transition and change the link destination
Change the file name and output destination of the JavaVM error file
[Rails] Change the label name of f.label
[Java] How to get the URL of the transition source
Get the URL of the HTTP redirect destination in Java
[Rails] How to change the column name of the table
Get the URL of the HTTP redirect destination in Ruby
rails path and url methods
[Ruby on Rails] Change the save destination of gem refile * Note
Change the save destination of the image to S3 in the Rails app. Part 2
[Ruby on Rails] How to make the link destination part of the specified id
[Rails 6] Change redirect destination at the time of new registration / login by devise
Change the port name and execution authority of the microcomputer connected to Ubuntu and LiDAR
Get the class name and method name of Controller executed by HandlerInterceptor of Spring Boot
Change the URL of the application of Eclipse project (Maven).
[Rails] I want to display the link destination of link_to in a separate tab
[Kotlin] Get the argument name of the constructor by reflection
[Rails] Addition of columns / Change of data type / column name
Get the name of the test case in the JUnit test class
[Ruby on Rails] How to change the column name
[Ruby on Rails] Change URL id to column name
[Rails] Cancel / change the default password validation of devise
Ruby, Nokogiri: Get the element name of the selected node
[Rails] How to get the contents of strong parameters
I can't get out of the Rails dbconsole screen
Get the object name of the instance created by the new operator
[Rails] When the layout change of devise is not reflected
[Android] Change the app name and app icon for each Flavor
[Rails] Get access_token at the time of Twitter authentication with Sorcery and save it in DB