[Ruby on Rails] How to make the link destination part of the specified id

Target

Clicking on a link will not scroll, even in the middle of the page Fly to the specified location.

Development environment

ruby 2.5.7 Rails 5.2.4.3 OS: macOS Catalina

① Specify id

Specify the id class where you want to skip.

erb:app/views/homes/about.html.erb


<div id="map"></div>

② Edit link_to

python


<%= link_to "Link name",Linked path(anchor: "Specified id name") %>

The actual description is as follows.

python


<%= link_to about_path(anchor: "map") do %>
  ACCSESS
<% end %>

Or

python


<%= link_to "ACCSESS", about_path(anchor: "map") %>

The URL looks like this.

http://localhost:3000/about#map

reference

Specify the location (position) of the destination page using Rails anchor link

Recommended Posts

[Ruby on Rails] How to make the link destination part of the specified id
part of the syntax of ruby ​​on rails
How to solve the local environment construction of Ruby on Rails (MAC)!
[Ruby On Rails] How to search the contents of params using include?
[Ruby on Rails] How to change the column name
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
How to use Ruby on Rails
(Ruby on Rails6) Display of the database that got the id of the database
[Ruby On Rails] How to search and save the data of the parent table from the child table
[Ruby on Rails] How to use CarrierWave
[Ruby on Rails] Change the save destination of gem refile * Note
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku
[Ruby on Rails] "|| =" ← Summary of how to use this assignment operator
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
How to make an application with ruby on rails (assuming that the environment has been built)
How to debug the processing in the Ruby on Rails model only on the console
How to make the schema of the URL generated by Rails URL helper https
Change the save destination of the image to S3 in the Rails app. Part 2
[Rails] How to decide the destination by "rails routes"
[Ruby on Rails] How to display error messages
[Ruby on Rails] Until the introduction of RSpec
How to add / remove Ruby on Rails columns
[Ruby on Rails] How to install Bootstrap in Rails
[Ruby on Rails] How to use session method
How to resolve errors that occur in the "Ruby on Rails" integration test
How to make a unique combination of data in the rails intermediate table
[Ruby on Rails] How to write enum in Japanese
Docker the development environment of Ruby on Rails project
[Ruby] How to find the sum of each digit
[Ruby on Rails] Change URL id to column name
[Rails] How to change the column name of the table
[Ruby On Rails] How to reset DB in Heroku
[Rails] How to get the contents of strong parameters
[Swift] How to get the document ID of Firebase
(Ruby on Rails6) How to create models and tables
Try using the query attribute of Ruby on Rails
[Ruby On Rails] How to use simple_format to display the entered text with line breaks
[Rails] I want to display the link destination of link_to in a separate tab
[Rails] How to make seed
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~
[Ruby On Rails] How to retrieve and display column information of multiple records linked to a specific id at once
[Ruby on Rails] Elimination of Fat Controller-First, logic to model-
Delete all the contents of the list page [Ruby on Rails]
A note about the seed function of Ruby on Rails
How to display a graph in Ruby on Rails (LazyHighChart)
[Note] About the Fizz_Buzz problem (How Ruby on Rails works)
[Ruby] How to retrieve the contents of a double hash
Let's summarize how to extend the expiration date of Rails
[Rails] How to display the list of posts by category
How to run React and Rails on the same server
How to check the database of apps deployed on Heroku
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
[Ruby On Rails] How to update the calculated result to an integer type column using update_column
How to deploy jQuery on Rails
Basic knowledge of Ruby on Rails
How to deploy Bootstrap on Rails
Rails on Tiles (how to write)
[Swift] How to dynamically change the height of the toolbar on the keyboard
[Rails] How to get the URL of the transition source and redirect