Note that there are some explanatory texts on larger screens.

plurals
  1. POtrying to find an user by email an get "Called id for nil"
    primarykey
    data
    text
    <p>Hi I'm working on a reset password action. But after click the button I get this error:</p> <blockquote> <p>Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id</p> </blockquote> <p>Here is my password_reset_controller</p> <pre><code> class PasswordResetsController &lt; ApplicationController layout "sessions" def new end def create user = User.find_by_email(params[:email]) user.send_password_reset if user redirect_to root_url, :notice =&gt; "#{user.id}Las instrucciones para reestrablecer la contrasena fueron enviadas." end end </code></pre> <p>and Here is my user model</p> <pre><code>class User &lt; ActiveRecord::Base attr_accessible :email, :password, :password_confirmation has_secure_password before_save { |user| user.email = email.downcase } before_save :create_remember_token VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } validates :password, presence: true, length: { minimum: 6 } validates :password_confirmation, presence: true def send_password_reset self.password_reset_token = SecureRandom.urlsafe_base64 self.password_reset_at = Time.zone.now save! end private def create_remember_token self.remember_token = SecureRandom.urlsafe_base64 end end </code></pre> <p>this is the view:</p> <pre><code>&lt;% provide(:title, "Reiniciar Password") %&gt; &lt;div class="row"&gt; &lt;div class="span4"&gt; &amp;nbsp &lt;/div&gt; &lt;div class="span4" id="login-box"&gt; &lt;div id="login-controls"&gt; &lt;%= link_to(image_tag("logo.png"), root_path) %&gt; &lt;br&gt; &lt;br&gt; &lt;%= form_for(:password_resets, url: password_resets_path) do |f| %&gt; &lt;%= f.text_field :email, :placeholder =&gt; "Correo Electronico", :tabindex =&gt; 1, :style =&gt; "height:25px;" %&gt; &lt;%= f.button "&lt;i class=\"icon-lock icon-white\"&gt;&lt;/i&gt; Reiniciar Password".html_safe, :tabindex =&gt; 2, class: "btn btn-warning", :style =&gt; "width:220px;margin-bottom:5px;" %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="span4"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I don't understan why I can't find the user; I try to do the same at rails console and I can find the user by email, but I can generate the password_reset_token.</p> <p>Please I appreciate your help.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload