Jackson
Jackson

Reputation: 6851

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].

Upvotes: 0

Views: 522

Answers (1)

admanb
admanb

Reputation: 231

Why not just set another variable?

@filters = params

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

Upvotes: 1

Related Questions