[RUBY] How to have params in link_to method

environment

What you want to implement

Have params in the link_to method.

Setting

Describe what you want to pass as an argument to the path of the link_to method.

ruby:index.html.erb


<ul class="gender-lists">
  <li>
    <%= link_to "ALL", root_path, class:"gender" %>
  </li>   
  <li>
    <%= link_to "MEN", search_posts_path(gender_id: 2), class:"gender" %>
  </li>
  <li>
    <%= link_to "WOMEN", search_posts_path(gender_id: 3), class:"gender" %>
  </li>
</ul>

If you write params [: gender_id], you can receive it with the controller.

posts_controller.rb


def search
  @posts = Post.search(params[:gender_id])
end

Recommended Posts

How to have params in link_to method
How to use the link_to method
How to add characters to display when using link_to method
How to mock a super method call in PowerMock
How to create a method
How to use the getter / setter method (in object orientation)
How to use Lombok in Spring
How to use the include? method
How to use the form_with method
How to run JUnit in Eclipse
How to iterate infinitely in Ruby
[Rails] How to write in Japanese
How to run Ant in Gradle
How to master programming in 3 months
How to learn JAVA in 7 days
How to get parameters in Spark
How to install Bootstrap in Ruby
[Ruby] How to use any? Method
How to use InjectorHolder in OpenAM
How to introduce jQuery in Rails 6
How to use classes in Java?
How to name variables in Java
How to set Lombok in Eclipse
How to use Ruby inject method
How to concatenate strings in java
How to install Swiper in Rails
How to deal with 405 Method Not Allowed error in Tomcat + JSP
How to POST JSON in Java-Method using OkHttp3 and method using HttpUrlConnection-
[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
How to store the information entered in textarea in a variable in the method
[swift5] How to specify color in hexadecimal
How to implement search functionality in Rails
How to implement Kalman filter in Java
How to change app name in rails
How to get date data in Ruby
How to use custom helpers in rails
Note to have multiple values in HashMap
[Java] How to compare with equals method
How to reflect seeds.rb in production environment
How to use named volume in docker-compose.yml
How to filter JUnit Test in Gradle
How to insert a video in Rails
How to standardize header footer in Thymeleaf
How to use submit method (Java Silver)
[Rails] How to use the map method
How to add jar file in ScalaIDE
[Java] How to use the toString () method
[Swift] How to fix Label in UIPickerView
How to use Docker in VSCode DevContainer
How to use MySQL in Rails tutorial
How to fix system date in JUnit
How to implement coding conventions in Java
How to embed Janus Graph in Java
[rails] How to configure routing in resources
How to map tsrange type in Hibernate
How to get the date in java
How to implement ranking functionality in Rails
How to use environment variables in RubyOnRails
How to implement asynchronous processing in Outsystems
How to publish a library in jCenter