nicolasblanco/rails_param

params with value was overwrite by default

Closed this issue · 1 comments

Basic Info

  • rails_param Version: 0.10.2
  • Ruby Version: 2.3.8
  • Rails Version: 4.2.11

Issue description

param! :aa, String, required: true
param! :bb, String, required: false, default: lambda { params[:aa]}

I want to set params[:bb] to params[:aa] when params[:bb] was empty, but when I set :bb in request it was overwrite by lambda { params[:aa]}

Steps to reproduce

see Issue description

code

this code set value to default not check params[name] is empty.

module RailsParam
  module Param

        # set default
        if options[:default].respond_to?(:call)
          params[name] = options[:default].call
        elsif params[name].nil? && check_param_presence?(options[:default])
          params[name] = options[:default]
        end

  end
end

Hi @archfish and thanks for raising this, I completely agree with you this is not an expected behaviour, and it seems like you've already identified the culprit!
I'll run a deeper investigation and get it fixed