[RUBY] [Rails] When transitioning to a page with link_to, move to the specified location on the page

Even though I was researching hard, I couldn't solve it, but it was actually very easy. (My way of checking was bad)

1. Specify the id where you want to move

<div id="target">Destination</div> 

2. Set an anchor in the transition destination path of link_to

<%= link_to 'Transition to the destination',Transition destination path(anchor: 'target') %>

That's it!

However, it does not move like this time, It is more dynamic and longing to add animation and scroll automatically, and in that case I think that implementation using JS will be necessary, so I would like to learn that as well in the future.

** Articles that I referred to ** Specify the location (position) of the destination page using Rails anchor link Set Anchor with Rails link_to (https://qiita.com/tatsuya1156/items/595fe0df912c6c89f991)

Recommended Posts

[Rails] When transitioning to a page with link_to, move to the specified location on the page
[Rails] I want to add data to Params when transitioning with link_to
Determine the current page with Ruby on Rails
[Ruby On Rails / HTML] How to display the cursor (caret) at an appropriate place when displaying a web page
How to reduce the load on the program even a little when combining characters with JAVA
[Rails] What to do when the view collapses when a message is displayed with the errors method
I want to add a browsing function with ruby on rails
Logic to draw a circle with ASCII art on the console
Steps to build a Ruby on Rails development environment with Vagrant
(Ruby on Rails6) Create a function to edit the posted content
When a beginner makes a personal app with rails, the procedure to bring it to the starting point anyway.
When you want to add a string type column with a limited length with the `rails generate migration` command
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
What to do when "call'Hoge.connection' to establish a connection" appears on rails c
[Ruby on Rails] How to make the link destination part of the specified id
[Rails] Button to return to the top of the page
[Rails] How to write when making a subquery
Come out with a suffix on the method
When the Ruby on Rails terminal rolls back
Publish the app made with ruby on rails
Come out with a suffix on the method 2
pass two arguments to the URI with link_to
Try to summarize the common layout with rails
I made a portfolio with Ruby On Rails
[java tool] A useful tool when you want to send the ipmsg log of PC-A to the specified PC on a regular basis.
I want to solve the problem that JS is not displayed properly unless reloaded when transitioning with Turbolinks: link_to
Rspec: I want to test the post-execution state when I set a method on subject
I tried to summarize the points to consider when acquiring location information with the iOS application ③
[Ruby On Rails] How to use simple_format to display the entered text with line breaks
I tried to summarize the points to consider when acquiring location information with the iOS application ①
How to save a file with the specified extension under the directory specified in Java to the list
When importing CSV with Rails, it was really easy to use the nkf command
A memo to do for the time being when building CentOS 6 series with VirtualBox
I tried to summarize the points to consider when acquiring location information with the iOS application ②
[Rails] I want to display the link destination of link_to in a separate tab
I want to hit the API with Rails on multiple docker-composes set up locally
[Rails] How to solve the error "undefined method` visit'" when using Capybara with Rspec
A warning is displayed when trying to use a huge integer with the special variables $ 1, $ 2, $ 3 ...
[Introduction] Try to create a Ruby on Rails application
How to delete a new_record object built with Rails
How to make an almost static page with rails
[Ruby on Rails] How to change the column name
Error encountered with notes when deploying docker on rails
How to make JavaScript work on a specific page
How to manually generate a JWT with Rails Knock
Transit to confirmation page when logging out with devise
What to do when rails creates a 〇〇 2.rb file
[How to insert a video in haml with Rails]
Challenge the settings for developing with vue.js on Rails 6
Addicted to the webpacker that comes standard with Rails 6
How to get started with creating a Rails app
When the server does not start with rails s
[Ruby on Rails] I get a warning when executing RSpec due to a different gem version.
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
Implemented a strong API for "I want to display ~~ on the screen" with simple CQRS
What to do when Rails on Docker does not reflect controller changes in the browser
Workspace setting location when connecting remotely with VS Code and working on a Docker container
How to transition from the [Swift5] app to the iPhone settings screen
I want to transition to the same screen in the saved state
[Rails] How to prevent screen transition
How to switch the display of the header menu for each transition page
How to pass the value to another screen
Fix the view screen of the post page
[Error] How to resolve the event that the screen does not transition after editing
[Rails] When transitioning to a page with link_to, move to the specified location on the page
How to automatically generate ER diagram when migrating with Rails6
[Rails] Processing after adding a column to the devise table
How to take a screenshot with the Android Studio emulator