lib/synvert/snippets/rails/strong_parameters.rb in synvert-0.0.11 vs lib/synvert/snippets/rails/strong_parameters.rb in synvert-0.0.12

- old
+ new

@@ -2,13 +2,11 @@ within_files 'config/**/*.rb' do # remove config.active_record.whitelist_attributes = ... with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'whitelist_attributes=' do remove end - end - within_files 'config/**/*.rb' do # remove config.active_record.mass_assignment_sanitizer = ... with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'mass_assignment_sanitizer=' do remove end end @@ -30,12 +28,13 @@ object_name = node.name.source(self).sub('Controller', '').singularize.underscore if_exist_node type: 'send', receiver: 'params', message: '[]', arguments: [object_name.to_sym] do if parameters[object_name] # append def xxx_params; ...; end unless_exist_node type: 'def', name: "#{object_name}_params" do - append """def #{object_name}_params - params.require(:#{object_name}).permit(#{parameters[object_name]}) -end""" + new_code = "def #{object_name}_params\n" + new_code << " params.require(:#{object_name}).permit(#{parameters[object_name]})\n" + new_code << "end" + append new_code end # params[:xxx] => xxx_params with_node type: 'send', receiver: 'params', message: '[]' do object_name = eval(node.arguments.first.source(self)).to_s