Rapture
Rapture

Reputation: 1896

check_box_tag default checked for remember me

I am creating a login system and would have a remember me checkbox. I would like to make this checkbox default to checked so that the user can uncheck if they do NOT want to be remembered.

Currently I have

<%= label_tag :remember_me %>
<%= check_box_tag :remember_me, 1, params[:remember_me] %>

How do I add the option to default this to checked?

This seems like it should be simple, but I've tried looking at the api and monkeying with my code to make it work, but no luck! Any help would be greatly appreciated.

Upvotes: 7

Views: 13783

Answers (3)

edx
edx

Reputation: 1347

# view:
<%= check_box_tag(:flag, 'yes', @flag) %>

# controller:
def foo
  @flag = params[:flag] || !params[:utf8]
end

Upvotes: 0

PlankTon
PlankTon

Reputation: 12605

This should work.

 <%= check_box_tag :remember_me, :checked => true %>

Upvotes: 11

dexter
dexter

Reputation: 13593

Set params[:remember_me] = true in your controller action before rendering this view.

Upvotes: 9

Related Questions