nulltek
nulltek

Reputation: 3337

Rails testing for params key

I'm trying to sort out a problem where I need to write the following and test to see if a params key is being passed:

if params.has_key? :transfer_date(1i)
    params[:call].parse_time_select! :transfer_date
  end

I can test against a params key like :transfer but the params being passed by my time parsing gem passes transfer_date(1i), transfer_date(2i), etc.

How do I write the above statement with the right syntax so I can test for the transfer_date(1i) params key?

Upvotes: 0

Views: 1026

Answers (1)

mu is too short
mu is too short

Reputation: 434665

You can quote the symbol's content:

if params.has_key? :'transfer_date(1i)'

or, if params is guaranteed to be the usual ActiveSupport::HashWithIndifferentAccess, you could just check for a string key:

if params.has_key? 'transfer_date(1i)'

Upvotes: 2

Related Questions