Learning Devise for Rails

75 views
Skip to first unread message

Greg Bressler

unread,
Jun 10, 2015, 5:58:47 AM6/10/15
to rubyonra...@googlegroups.com
I'm new to rails and was trying to get a handle on Devise. I'm
following the Packt Pub - Learning Devise For Rails tutorial and have a
problem around pg 19-20 (CH2). I've created a user, logged out, but
when I try to login again I get this error:

NameError in Devise::SessionsController#create
undefined local variable or method `signin' for
#<Class:0x00000004352b00>

I was confused because I see "Sessions Controller" in the error, but the
code lists is in my devise user model:

class User < ActiveRecord::Base

# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

attr_accessor :signin

validates :username, :uniqueness => {:case_sensitive => false}

def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
where(conditions).where(["lower(username) = :value
OR lower(email) = :value", { :value => signin.downcase }]).first
end

end

Here's a link to everything I have so far:
https://github.com/GBressler/Learning-Devise-for-Rails/tree/master/Ch2/first_app_extensions

The tutorial:
https://www.packtpub.com/application-development/learning-devise-rails

Any help that could be provided would be greatly appreciated!

Attachments:
http://www.ruby-forum.com/attachment/10847/Screenshot_from_2015-06-08_22_52_49.jpg


--
Posted via http://www.ruby-forum.com/.

Emmanuel Abia

unread,
Jun 10, 2015, 6:50:45 AM6/10/15
to rubyonra...@googlegroups.com
If you are using Rails 4+, you need to read the Strong parameter section of the Devise github page here

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8654055c5ad229b25e10845d87eea3e6%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Walter Lee Davis

unread,
Jun 10, 2015, 7:28:25 AM6/10/15
to rubyonra...@googlegroups.com

On Jun 10, 2015, at 5:58 AM, Greg Bressler <li...@ruby-forum.com> wrote:

> I'm new to rails and was trying to get a handle on Devise. I'm
> following the Packt Pub - Learning Devise For Rails tutorial and have a
> problem around pg 19-20 (CH2). I've created a user, logged out, but
> when I try to login again I get this error:
>
> NameError in Devise::SessionsController#create
> undefined local variable or method `signin' for
> #<Class:0x00000004352b00>
>
> I was confused because I see "Sessions Controller" in the error, but the
> code lists is in my devise user model:
>
> class User < ActiveRecord::Base
>
> # Include default devise modules. Others available are:
> # :confirmable, :lockable, :timeoutable and :omniauthable
> devise :database_authenticatable, :registerable,
> :recoverable, :rememberable, :trackable, :validatable
>
> attr_accessor :signin

What is this attar_accessor supposed to do? Do you set it to a value at any point? This is not a part of Devise, as far as I can tell.

Walter


>
> validates :username, :uniqueness => {:case_sensitive => false}
>
> def self.find_first_by_auth_conditions(warden_conditions)
> conditions = warden_conditions.dup
> where(conditions).where(["lower(username) = :value
> OR lower(email) = :value", { :value => signin.downcase }]).first
> end
>
> end
>
> Here's a link to everything I have so far:
> https://github.com/GBressler/Learning-Devise-for-Rails/tree/master/Ch2/first_app_extensions
>
> The tutorial:
> https://www.packtpub.com/application-development/learning-devise-rails
>
> Any help that could be provided would be greatly appreciated!
>
> Attachments:
> http://www.ruby-forum.com/attachment/10847/Screenshot_from_2015-06-08_22_52_49.jpg
>
>
> --
> Posted via http://www.ruby-forum.com/.
>

Elizabeth McGurty

unread,
Jun 10, 2015, 8:50:29 AM6/10/15
to rubyonra...@googlegroups.com
I found this link very interesting:

https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address

I don't know the dynamics of Devise, but I looked at your application:
2 controllers: application and home.  home has show, new, edit defs.  All empty
1 model user
3 view folders: devise, home, layouts.
Devise has folder session with new.html.erb.  It has:
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div class="field"> <%= f.label "Username or Email" %><br /> <%= f.text_field :signin, autofocus: true %> </div>
 Where have you defined resource? 

Greg Bressler

unread,
Jul 19, 2015, 7:00:38 PM7/19/15
to rubyonra...@googlegroups.com
Thanks for the help, everyone. After following the link to github that
Elizabeth posted I was able to cut and paste some updated code.

Thanks again.
Reply all
Reply to author
Forward
0 new messages