Skip to content

Instantly share code, notes, and snippets.

@emanuelhfarias
Created February 13, 2017 03:01
Show Gist options
  • Save emanuelhfarias/ca20acc392497268397bb80f856a89b5 to your computer and use it in GitHub Desktop.
Save emanuelhfarias/ca20acc392497268397bb80f856a89b5 to your computer and use it in GitHub Desktop.
[Rails] Valid params.permit mantaining the order of params
params = ActionController::Parameters.new( {sort: {year: 'desc', title: 'asc', author: 'desc'}} )
valid_sorts = ["author", "title", "year"]
passed_sorts = params[:sort].keys & valid_sorts # only permit valid sorts
params.permit(sort: passed_sorts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment