I'm using Authlogic with Rails 3.0 and I'm having an issue where my users
can't login. I have a customer model and a user model and in production my
customer login works, but my user login doesn't (in development both work
fine). Someone please help, users generally frown upon not being able to
login.

What happens is that when user_sessions tries to save it fails.
Specifically, my Heroku logs say:

Started POST "user_sessions"
POST myapp.com/user_sessions
ArgumentError (invalid date)
config/initializers/american_date_monkey_patch.rb:11:in 'to_date'
config/initializers/american_date_monkey_patch.rb:17:in 'fallback_string_to_date'
app/controllers/user_sessions_controller.rb:in 'create'

american_date_monkey_patch.rb

if RUBY_VERSION >= '1.9'
class String
def to_date
if self.blank?
nil
elsif self =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/
::Date.civil($3.to_i, $1.to_i, $2.to_i)
else
::Date.new(*::Date._parse(self, false).values_at(:year, :mon, :mday))
end
end
end

class ActiveRecord::ConnectionAdapters::Column
def self.fallback_string_to_date(string)
string.to_date
end
end
end

user_sessions model

class UserSession < Authlogic::Session::Base
def to_key
new_record? ? nil : [ self.send(self.class.primary_key) ]
end

def persisted?
false
end
end

customer_sessions model (same as above with a different class name)

class CustomerSession < Authlogic::Session::Base
def to_key
new_record? ? nil : [ self.send(self.class.primary_key) ]
end

def persisted?
false
end
end

user_sessions controller

class UserSessionsController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => :destroy

def new
@user_session = UserSession.new
end

def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Login successful!"
redirect_back_or_default community_path
else
render :action => :new
end
end

def destroy
current_user_session.destroy
flash[:notice] = "Logout user successful!"
redirect_back_or_default community_path
end
end

Customer Sessions controller (similar but not identical)

class CustomerSessionsController < ApplicationController

def new
@customer_session = CustomerSession.new
end

def create
@customer_session = CustomerSession.new(params[:customer_session])
if @customer_session.save
flash[:notice] = "Login successful!"
redirect_back_or_default admins_path
else
render :action => :new
end
end

def destroy
current_customer_session.destroy
flash[:notice] = "Logout customer successful!"
redirect_back_or_default admins_path
end
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/lKmuBA4Wid8J.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Mar 7, 2012 at 9:08 am

    On 7 March 2012 05:29, yellowreign wrote:
    I'm using Authlogic with Rails 3.0 and I'm having an issue where my users
    can't login. I have a customer model and a user model and in production my
    customer login works, but my user login doesn't (in development both work
    fine). Someone please help, users generally frown upon not being able to
    login.
    When you say it works in development mode is that in the same
    environment or are you comparing development on one system with
    production on another?
    What happens is that when user_sessions tries to save it fails.
    Specifically, my Heroku logs say:

    Started POST "user_sessions"
    POST myapp.com/user_sessions
    ArgumentError (invalid date)
    config/initializers/american_date_monkey_patch.rb:11:in 'to_date'
    config/initializers/american_date_monkey_patch.rb:17:in
    'fallback_string_to_date'
    app/controllers/user_sessions_controller.rb:in 'create'

    american_date_monkey_patch.rb

    if RUBY_VERSION >= '1.9'
    Are you sure you are using the same version of ruby in production and
    development? If not then the difference may be whether this code is
    getting invoked.
    class String
    def to_date
    if self.blank?
    nil
    elsif self =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/
    ::Date.civil($3.to_i, $1.to_i, $2.to_i)
    else
    ::Date.new(*::Date._parse(self, false).values_at(:year, :mon,
    :mday))
    One of the two lines above is failing (not sure which as not sure
    which as line 11 (from the error) does not seem to match either of
    them exactly. If you still can't work out what is going on then put
    some debug in to work it out. See the Rails Guide on debugging for
    clues on how to do that.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Ryan Chin at Mar 7, 2012 at 3:34 pm
    They're using different environments - development is on my PC, production
    is on Heroku.
    On Wed, Mar 7, 2012 at 1:07 AM, Colin Law wrote:
    On 7 March 2012 05:29, yellowreign wrote:
    I'm using Authlogic with Rails 3.0 and I'm having an issue where my users
    can't login. I have a customer model and a user model and in production my
    customer login works, but my user login doesn't (in development both work
    fine). Someone please help, users generally frown upon not being able to
    login.
    When you say it works in development mode is that in the same
    environment or are you comparing development on one system with
    production on another?
    What happens is that when user_sessions tries to save it fails.
    Specifically, my Heroku logs say:

    Started POST "user_sessions"
    POST myapp.com/user_sessions
    ArgumentError (invalid date)
    config/initializers/american_date_monkey_patch.rb:11:in 'to_date'
    config/initializers/american_date_monkey_patch.rb:17:in
    'fallback_string_to_date'
    app/controllers/user_sessions_controller.rb:in 'create'

    american_date_monkey_patch.rb

    if RUBY_VERSION >= '1.9'
    Are you sure you are using the same version of ruby in production and
    development? If not then the difference may be whether this code is
    getting invoked.
    class String
    def to_date
    if self.blank?
    nil
    elsif self =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/
    ::Date.civil($3.to_i, $1.to_i, $2.to_i)
    else
    ::Date.new(*::Date._parse(self, false).values_at(:year, :mon,
    :mday))
    One of the two lines above is failing (not sure which as not sure
    which as line 11 (from the error) does not seem to match either of
    them exactly. If you still can't work out what is going on then put
    some debug in to work it out. See the Rails Guide on debugging for
    clues on how to do that.

    Colin

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.

    --
    Thanks,
    Ryan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Mar 7, 2012 at 3:38 pm
    On 7 March 2012 15:33, Ryan Chin wrote:

    Please don't top post, it makes it difficult to follow the thread,
    insert you reply into the previous post at appropriate points.
    Thanks.
    They're using different environments - development is on my PC, production
    is on Heroku.
    And the answers to my other questions?

    Colin
    On Wed, Mar 7, 2012 at 1:07 AM, Colin Law wrote:
    On 7 March 2012 05:29, yellowreign wrote:
    I'm using Authlogic with Rails 3.0 and I'm having an issue where my
    users
    can't login. I have a customer model and a user model and in production
    my
    customer login works, but my user login doesn't (in development both
    work
    fine). Someone please help, users generally frown upon not being able to
    login.
    When you say it works in development mode is that in the same
    environment or are you comparing development on one system with
    production on another?
    What happens is that when user_sessions tries to save it fails.
    Specifically, my Heroku logs say:

    Started POST "user_sessions"
    POST myapp.com/user_sessions
    ArgumentError (invalid date)
    config/initializers/american_date_monkey_patch.rb:11:in 'to_date'
    config/initializers/american_date_monkey_patch.rb:17:in
    'fallback_string_to_date'
    app/controllers/user_sessions_controller.rb:in 'create'

    american_date_monkey_patch.rb

    if RUBY_VERSION >= '1.9'
    Are you sure you are using the same version of ruby in production and
    development?  If not then the difference may be whether this code is
    getting invoked.
    class String
    def to_date
    if self.blank?
    nil
    elsif self =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/
    ::Date.civil($3.to_i, $1.to_i, $2.to_i)
    else
    ::Date.new(*::Date._parse(self, false).values_at(:year, :mon,
    :mday))
    One of the two lines above is failing (not sure which as not sure
    which as line 11 (from the error) does not seem to match either of
    them exactly.  If you still can't work out what is going on then put
    some debug in to work it out.  See the Rails Guide on debugging for
    clues on how to do that.

    Colin

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    Thanks,
    Ryan

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    gplus.to/clanlaw

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Yellowreign at Mar 8, 2012 at 3:44 am

    On Wednesday, March 7, 2012 7:37:58 AM UTC-8, Colin Law wrote:
    On 7 March 2012 15:33, Ryan Chin wrote:

    Please don't top post, it makes it difficult to follow the thread,
    insert you reply into the previous post at appropriate points.
    Thanks.
    They're using different environments - development is on my PC,
    production
    is on Heroku.
    And the answers to my other questions?

    Colin
    Hi Colin, I think you're right. I'm running 1.8.7 locally, but my Heroku
    stack is 1.9.2.

    So my next newbie questions is how do I get my current local app to use the
    1.9.2 that I installed (downloaded from http://rubyinstaller.org)? Is
    there some place to map my development environment to the new 1.9.2
    install? After I installed Ruby, I went into the command prompt to run
    rails s, and I got this message, "report_activate_error: Could not find
    RubyGem rails <>=0

    I tried searching, but couldn't find anything except this:
    http://stackoverflow.com/questions/2741180/how-do-i-upgrade-from-ruby-1-8-6-to-1-8-7-on-windows

    and the extent of it is download Ruby 1.9.2 and install.

    Thank you
    On Wed, Mar 7, 2012 at 1:07 AM, Colin Law wrote:
    On 7 March 2012 05:29, yellowreign wrote:
    I'm using Authlogic with Rails 3.0 and I'm having an issue where my
    users
    can't login. I have a customer model and a user model and in
    production
    my
    customer login works, but my user login doesn't (in development both
    work
    fine). Someone please help, users generally frown upon not being able
    to
    login.
    When you say it works in development mode is that in the same
    environment or are you comparing development on one system with
    production on another?
    What happens is that when user_sessions tries to save it fails.
    Specifically, my Heroku logs say:

    Started POST "user_sessions"
    POST myapp.com/user_sessions
    ArgumentError (invalid date)
    config/initializers/american_date_monkey_patch.rb:11:in 'to_date'
    config/initializers/american_date_monkey_patch.rb:17:in
    'fallback_string_to_date'
    app/controllers/user_sessions_controller.rb:in 'create'

    american_date_monkey_patch.rb

    if RUBY_VERSION >= '1.9'
    Are you sure you are using the same version of ruby in production and
    development? If not then the difference may be whether this code is
    getting invoked.
    class String
    def to_date
    if self.blank?
    nil
    elsif self =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/
    ::Date.civil($3.to_i, $1.to_i, $2.to_i)
    else
    ::Date.new(*::Date._parse(self, false).values_at(:year, :mon,
    :mday))
    One of the two lines above is failing (not sure which as not sure
    which as line 11 (from the error) does not seem to match either of
    them exactly. If you still can't work out what is going on then put
    some debug in to work it out. See the Rails Guide on debugging for
    clues on how to do that.

    Colin

    --
    You received this message because you are subscribed to the Google
    Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    Thanks,
    Ryan

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    gplus.to/clanlaw
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/i3C7odx0ELsJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Mar 8, 2012 at 9:12 am

    On 8 March 2012 03:44, yellowreign wrote:
    On Wednesday, March 7, 2012 7:37:58 AM UTC-8, Colin Law wrote:

    On 7 March 2012 15:33, Ryan Chin wrote:

    Please don't top post, it makes it difficult to follow the thread,
    insert you reply into the previous post at appropriate points.
    Thanks.
    They're using different environments - development is on my PC,
    production
    is on Heroku.
    And the answers to my other questions?

    Colin
    Hi Colin, I think you're right.  I'm running 1.8.7 locally, but my Heroku
    stack is 1.9.2.

    So my next newbie questions is how do I get my current local app to use the
    1.9.2 that I installed (downloaded from http://rubyinstaller.org)?  Is there
    some place to map my development environment to the new 1.9.2 install?
    After I installed Ruby, I went into the command prompt to run rails s, and
    I got this message, "report_activate_error: Could not find RubyGem rails
    <>=0

    I tried searching, but couldn't find anything except
    this: http://stackoverflow.com/questions/2741180/how-do-i-upgrade-from-ruby-1-8-6-to-1-8-7-on-windows
    Sorry, if you are on Windows I can't help. Most Rails developers use
    Linux (I use Ubuntu) or Mac. You will have to hope someone here who
    uses Windows can help, or alternatively (which would be my suggestion)
    set up your machine to dual boot Win and Ubuntu, or run Ubuntu in a
    virtual machine using VirtualBox or VMWare.

    There is however the question of why you are using
    american_date_monkey_patch (which I know nothing about) since it seems
    to be that that is causing the problem.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Yellowreign at Mar 8, 2012 at 6:28 pm

    On Thursday, March 8, 2012 1:11:16 AM UTC-8, Colin Law wrote:
    On 8 March 2012 03:44, yellowreign wrote:

    On Wednesday, March 7, 2012 7:37:58 AM UTC-8, Colin Law wrote:

    On 7 March 2012 15:33,

    Please don't top post, it makes it difficult to follow the thread,
    insert you reply into the previous post at appropriate points.
    Thanks.
    They're using different environments - development is on my PC,
    production
    is on Heroku.
    And the answers to my other questions?

    Colin
    Hi Colin, I think you're right. I'm running 1.8.7 locally, but my Heroku
    stack is 1.9.2.

    So my next newbie questions is how do I get my current local app to use the
    1.9.2 that I installed (downloaded from http://rubyinstaller.org)? Is there
    some place to map my development environment to the new 1.9.2 install?
    After I installed Ruby, I went into the command prompt to run rails s, and
    I got this message, "report_activate_error: Could not find RubyGem rails
    <>=0

    I tried searching, but couldn't find anything except
    this:
    http://stackoverflow.com/questions/2741180/how-do-i-upgrade-from-ruby-1-8-6-to-1-8-7-on-windows

    Sorry, if you are on Windows I can't help. Most Rails developers use
    Linux (I use Ubuntu) or Mac. You will have to hope someone here who
    uses Windows can help, or alternatively (which would be my suggestion)
    set up your machine to dual boot Win and Ubuntu, or run Ubuntu in a
    virtual machine using VirtualBox or VMWare.

    Hi Colin,
    To be honest, this is the first time I developed something - I only started
    learning because my developer left me. I did some research and it seems
    like the purpose is to parse the date fields considering it is entered in
    an American format (and then saving to the database). However, I dug
    around and found this gem https://github.com/jeremyevans/ruby-american_date which
    I could probably use instead.

    There is however the question of why you are using
    american_date_monkey_patch (which I know nothing about) since it seems
    to be that that is causing the problem.

    Colin
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/n8EVZVaV9GQJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 7, '12 at 5:29a
activeMar 8, '12 at 6:28p
posts7
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Yellowreign: 4 posts Colin Law: 3 posts

People

Translate

site design / logo © 2021 Grokbase