Forum: Ruby on Rails How do you deal with non-model property form values

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Paul B. (Guest)
on 2006-01-21 23:05
(Received via mailing list)
I have a User ActiveRecord model that has email and password properties.
want to build a login for that has a "remember me" option.  My view
like this:

<% @page_title = "Login" -%>
<%= error_messages_for 'user' %>
<%= form_tag %>
    <td align="right" width="1%" nowrap="nowrap"><label class="required"
    <td><%= text_field("user", "email") %></td>
    <td align="right" width="1%" nowrap="nowrap"><label class="required"
    <td><%= password_field("user", "password") %></td>
    <td align="right"><input type="checkbox" id="remember"
    <td><label for="remember">Automatically log me in on this
    <td><input type="submit" value="Login" /></td>
<%= end_form_tag %>

I would like to use the check_box FormHelper method, but remember is not
property of the User object, and I would rather not add it, since it
real make sense.  What's the best way to handle this?
Ben R. (Guest)
on 2006-01-21 23:12
(Received via mailing list)
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


Hope this helps,

~ Ben
Bill K. (Guest)
on 2006-01-22 07:26
(Received via mailing list)
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
all the form helpers with _tag endings are useful for instance variables
that are bookkeeping and not part of your real model.
Paul B. (Guest)
on 2006-01-23 18:56
(Received via mailing list)
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 =[:user])[:form][:remember])
      flash[:notice] = "Invalid username/password"

when i submit the form, the form.remember value of 1 prints out, if I
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
the checkbox correctly.
Alex Y. (Guest)
on 2006-01-23 18:59
(Received via mailing list)
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,

<%= check_box_tag('form[remember]', params[:form][:remember]) %>

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

Paul B. (Guest)
on 2006-01-23 19:08
(Received via mailing list)
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
using :extradata).  That seems unnecessary.  So I removed that hand
the controller to just call params[:remember].

Thanks for your help everyone
This topic is locked and can not be replied to.