6

我的模板如下所示:

.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

它确实有效,但它会生成两个具有重复 ID 的表单,例如...

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

如何更改此设置以使 ID 不重复?

4

2 回答 2

5

您可以将命名空间添加到表单中。

=form_for(:user, :as => :user_forgot, :url => password_path(:user), :namespace => 'forgot', :html => { :method => :post }) do |f|
于 2012-12-24T19:03:33.620 回答
0

如果您不喜欢涉及名称空间,可以尝试 AJAX 请求。这将保证您可以在形成 POST 请求时重命名字段。

或者您可以覆盖 Devise 的默认 PasswordsController 并编写自己的方法来恢复密码。对于您的覆盖,您可以简单地从 {RubyFolder}/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/controllers/devise/passwords_controller.rb 借用一些方法的代码,并为您的应用程序(例如,重命名预期的输入参数)。

于 2012-12-26T14:38:07.727 回答