Created
February 13, 2017 03:01
-
-
Save emanuelhfarias/ca20acc392497268397bb80f856a89b5 to your computer and use it in GitHub Desktop.
[Rails] Valid params.permit mantaining the order of params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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