# How do you deal with non-model property form values

**URL:** <https://www.ruby-forum.com/t/how-do-you-deal-with-non-model-property-form-values/63830>\
**Category:** Rails\
**Created:** [January 21, 2006, 10:05pm UTC](https://www.ruby-forum.com/t/how-do-you-deal-with-non-model-property-form-values/63830 "2006-01-21T22:05:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [January 21, 2006, 10:05pm UTC](https://www.ruby-forum.com/t/how-do-you-deal-with-non-model-property-form-values/63830/1 "2006-01-21T22:05:43Z")

</div>

I have a User ActiveRecord model that has email and password properties.  
I  
want to build a login for that has a “remember me” option. My view  
looks  
like this:

\<% @page\_title = “Login” -%\>  
\<%= error\_messages\_for ‘user’ %\>  
\<%= form\_tag %\>

| Email: | \<%= text\_field("user", "email") %\> |
| Password: | \<%= password\_field("user", "password") %\> |
| | Automatically log me in on this computer |
| &nbsp; | |

\<%= end\_form\_tag %\>

I would like to use the check\_box FormHelper method, but remember is not  
a  
property of the User object, and I would rather not add it, since it  
doesn’t  
real make sense. What’s the best way to handle this?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [January 21, 2006, 10:12pm UTC](https://www.ruby-forum.com/t/how-do-you-deal-with-non-model-property-form-values/63830/2 "2006-01-21T22:12:06Z")

</div>

Hi Paul ~

You can pass it back in a separate hash. So you could set name =  
extradata[remember], then access it separately from your user items in  
the  
form.

params[:extradata][:remember]

Hope this helps,

~ Ben

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [January 22, 2006, 6:26am UTC](https://www.ruby-forum.com/t/how-do-you-deal-with-non-model-property-form-values/63830/3 "2006-01-22T06:26:08Z")

</div>

Use check\_box\_tag() and an instance variable that isn’t in your User  
object. Like Ben says, it will still be accessible from params. In  
general,  
all the form helpers with \_tag endings are useful for instance variables  
that are bookkeeping and not part of your real model.  
-Bill

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [January 23, 2006, 5:59pm UTC](https://www.ruby-forum.com/t/how-do-you-deal-with-non-model-property-form-values/63830/4 "2006-01-23T17:59:31Z")

</div>

Paul B. wrote:

> Ok, so I did this in my index.rhtml:
> 
> \<%= check\_box(“form”,“remember”) %\>  
> That looks for an instance variable called @form with a method called  
> ‘remember’. What you probably want, judging by your controller code,  
> is:

\<%= check\_box\_tag(‘form[remember]’, params[:form][:remember]) %\>

And then remember to default it on the first time in your action.

–  
Alex

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [January 23, 2006, 6:08pm UTC](https://www.ruby-forum.com/t/how-do-you-deal-with-non-model-property-form-values/63830/5 "2006-01-23T18:08:42Z")

</div>

Yeah, I just set it to do this:

\<%= check\_box\_tag(“remember”,1,params[:remember]) %\>

I was using :form because that was Ben’s suggestion (he actually  
suggested  
using :extradata). That seems unnecessary. So I removed that hand  
modified  
the controller to just call params[:remember].

Thanks for your help everyone

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [January 23, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/how-do-you-deal-with-non-model-property-form-values/63830/6 "2006-01-23T17:56:27Z")

</div>

Ok, so I did this in my index.rhtml:

\<%= check\_box(“form”,“remember”) %\>

And then my controller method looks like this:

def index  
if request.get?  
@user = User.new  
else  
@user = User.new(params[:user])  
logger.info(params[:form][:remember])  
flash[:notice] = “Invalid username/password”  
end  
end

when i submit the form, the form.remember value of 1 prints out, if I  
check  
the remeber checkbox. But when the form renders again, the checkbox is  
unchecked. Shouldn’t check\_box handle setting the value of the checkbox  
correctly? I also tried check\_box\_tag, but neither one sets the value  
of  
the checkbox correctly.
