Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Devise: how do I place the login form and the recover password on the same page?

My template looks like this:

.dropdown.light
      .login
        =form_for("user", :url => user_session_path) do |f|
          = f.hidden_field :redirect_to, :value => request.fullpath
          = f.email_field :email, :placeholder => "email", :size => ''
          = f.password_field :password, :placeholder => "password", :size => ''
          div.remember
            = f.check_box :remember_me, :checked => "checked"
            = f.label :remember_me
          .clearfix
            a.forgot.pull-left href="#forgot" Forgot your password?
            input.pull-right type="submit" value="Sign in"
      .forgotten
        =form_for(:user,:as => :user_forgot, :url => password_path(:user), :html => { :method => :post }) do |f|
          p
            strong Reset your password
          p.small Give us your e-mail and you’ll be back in a jiffy
          div= f.email_field :email
          .clearfix
            a.forgot.nevermind.pull-left href="#forgot" Nevermind
            input.pull-right type="submit" value="Reset password"
      .sent
        p
          strong Email sent!
        p In a couple of minutes you should receive an email with a link to reset your password

It actually works, but it generates two forms with duplicate ids such as...

<input id="user_email" name="user[email]" size="30" type="email">

How do I change this so the IDs don't duplicate?

like image 452
methodofaction Avatar asked Dec 20 '12 21:12

methodofaction


1 Answers

You can add namespace to your forms.

=form_for(:user, :as => :user_forgot, :url => password_path(:user), :namespace => 'forgot', :html => { :method => :post }) do |f|
like image 90
taro Avatar answered Oct 05 '22 23:10

taro