# Determining the member type in Params Hash

**URL:** <https://www.ruby-forum.com/t/determining-the-member-type-in-params-hash/149221>\
**Category:** Rails\
**Created:** [September 22, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/determining-the-member-type-in-params-hash/149221 "2008-09-22T17:08:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [September 22, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/determining-the-member-type-in-params-hash/149221/1 "2008-09-22T17:08:15Z")

</div>

Is there an easy way to determine what is the “type” of a member in the  
Params hash? The reason that I ask this question is that I have to make  
adjustments for UK dates in the params hash for date and datetime  
fields.

The date and datetime fields are being returned as Strings. So when I  
assign the hash to an instance variable’s attributes as follows:

@entry.attributes = params[:entry]

for example. The program errors out. I have to Normalize the String  
representation of UK dates in in US dates (still String format) before  
the

```
lvar = params[:entry]
unless lvar[:example_date].nil?
  lvar[:date] = ParseDate.normalize_date(lvar[:example_date])
end
@entry.attributes = lvar

```

statement is executed and then everything works fine. But this is a lot  
of ugly duplicate coding accounting for specific members of params hash  
that are date and datetime type. I was hoping that there might be an  
elegant solution to this problem.  
Thanks in advance for your time.  
Bharat

---

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [September 22, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/determining-the-member-type-in-params-hash/149221/2 "2008-09-22T21:54:49Z")

</div>

Although my Rails-fu is only of moderate strength…

The only thing determining the expected type of a particular params hash  
value (they are all strings as you said) is the intended receiver…  
which sounds like a model to me (@entry)… which would make the  
translation from UK to US the model’s business… which would lead me to  
create a model method to employ between the params hash and the model  
assignment

@entry = Entry.new.localized ‘US’, params[:entry]

or something like that.

The localized method could check just the params attributes necessary  
(Entry knows which attributes it has to check, other models know their  
attributes), and the code that actually does the normalization per  
attribute might go in a helper, a module, or as part of a superclass  
between AR and Entry depending on how often it was used.

Fred probably has a better way though… 😉

---

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [September 23, 2008, 1:53am UTC](https://www.ruby-forum.com/t/determining-the-member-type-in-params-hash/149221/3 "2008-09-23T01:53:57Z")

</div>

Thanks Ar for your response. If someone can add a bit more clarity to  
this then I can run with it. Fred? Anyone?
