Pass parameters to Rails link_to

I want to pass parameters to the controller with gets using link_to

What you want to do

I want to pass the value when linking to the controller from the view side

Conclusion

Add it in the form of a hash to the argument of the path as shown below

* Example) When passing a value from top / index to top / link1

erb:top/index.html.erb


  <%= link_to "To link 1", top_link1_path(name: "piyo") %>

Receive parameters

top_controller


class TopController < ApplicationController
  def link1
    @params = params[:name]
  end
end

I searched a lot, but as a memorandum

Recommended Posts

Pass parameters to Rails link_to
[Rails] Add strong parameters to devise
[Ruby on Rails] Pass the parameters divided by date_select to FormObject.
pass two arguments to the URI with link_to
How to write Rails
Introducing CircleCI to Rails
Introducing Bootstrap to Rails 5
Introducing Bootstrap to Rails !!
Introduce Vue.js to Rails
About rails strong parameters
How to remove the underline displayed by Rails link_to
[Rails] How to get the contents of strong parameters
[Rails] How to use enum
How to read rails routes
What to check when rails db: migration does not pass
How to use rails join
[Rails] Add column to devise
[Rails] Specify format with link_to
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to disable turbolinks
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
[Rails] How to make seed
How to write Rails routing
[Rails] How to install simple_calendar
[Rails 5] How to use gem gon ~ How to pass variables from Rails to JS ~
[Rails] How to install reCAPTCHA
[Rails5] japanMap link How to write parameters in js.erb file
Introduced gRPC client to rails
Introduction to RSpec-Everyday Rails Summary-
[Rails] How to use Scope
Pass C ++ char * to Swift
[Rails] How to omit the display of the character string of the link_to method
I tried to understand how the rails method "link_to" is defined
[Rails] I want to add data to Params when transitioning with link_to
[Rails] What to do if you can't get parameters with form_with
How to use the link_to method
[Rails] How to use gem "devise"
How to deploy jQuery on Rails
[Rails] How to install Font Awesome
Rails new fails to install mysql
[Rails] How to use devise (Note)
[Rails] Two ways to write form_with
[Rails] How to use flash messages
[rails] How to display db information
Preparing to create a Rails application
[Rails] Learn yield to understand content_for
Introducing full calendar to Rails application
[Rails] How to prevent screen transition
[Rails] Various ways to delete data
How to use Ruby on Rails
[Rails] Easy way to check columns
How to deploy Bootstrap on Rails
Until you introduce fonts to Rails
[Rails] How to speed up docker-compose
[Rails] How to add new pages
[Rails] How to write exception handling?
[Rails] How to install Font Awesome