All Lessons / Link To Current Page With Params

Link To Current Page With Params

#270 ยท November 8, 2018

Your Teacher

Hi, I'm Chris. I'm the creator of GoRails, and Jumpstart. I spend my time creating tutorials and tools to help Ruby on Rails developers build apps better and faster.

About This Episode

Learn how to link to the current page and add, remove, or modify params in the URL. This is handy for things like search or index pages with filters.



For additional security, you should whitelist the params that you want to allow in the links.

# app/helpers/search_helper.rb
module SearchHelper
  def current_page_params
    # Modify this list to whitelist url params for linking to the current page
    request.params.slice("query", "filter", "sort")
<%= link_to "with foo", current_page_params.merge(foo: true) %>


logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.