Because params [: some_key] is String or ActionController :: Parameters, it's complicated.
class MyController < ApplicatinoController
def my_action
#
hash_of(params[:some_key]) #call
#
head: :no_content
end
private
def hash_of(param)
case param
when Hash #I haven't checked if there really is a hash.
param
when String
JSON.parse(param) #Throw an error if it's not a JSON string
when ApplicationController::Parameters
param.to_unsafe_h
end
end
end
Recommended Posts