Check ruby code

Hi, everyone!

I'm trying to check an array in Ruby code, but it's not working.
Could you check it together?

You want to save only if the keys you define are the same.

However, all parameters are currently stored.

kv {
source => "url_params"
field_split => "&"
value_split => "="
target => "url_params_hash"
}

ruby {
code => "
csa_fields = ['ip', 'mall_id', 'member_id']
event.get('url_params_hash').each do |k, v|
if csa_fields && csa_fields.each { |tk, tv| tv == k}
event.set(k, v)
end
end
"
}

Try this one :

ruby {
    code => "
        csa_fields = ['ip', 'mall_id', 'member_id']
        event.get('url_params_hash').to_hash.each { |k, v| event.set(k, v) if csa_fields.include?(k) }
    "
}

You only need to check each key inside the url_params_hash against your defined array.

1 Like

Good morning!
I thank you.
Since I am not familiar with ruby ​​code, I am having a lot of difficulties and I have not been able to fix the error.
I solved it with your help.

Good luck to you today.:+1:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.