简体   繁体   中英

Passing Params Back to View

I have a page with some filters (a form) in a Rails app. When the user submits, I filter out the data, but I want to pass the params back to the page, so that the filters are still set to what they selected. How can I pass params back to the same page they came from?

UPDATE:

My controller action looks like this:

Sure. My index controller action looks like this:

 country = params[:country][:id] if params[:country].present?
    @data = Game.where("date BETWEEN ? AND ?", *date_range_array)
            .by_code(params[:code])
            .by_country(country)
            .includes(:country_index)
            .order(sort_column + " " + sort_direction)
            .page(params[:page])

I would like to pass back to my index view the params[:country] and params[:code].

Why not just set another variable?

@filters = params

Then in your view you can access @filters[:country] and @filters[:code].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM