Question

I am stuck in really weird issue. i have the following code in my SessionsController

def create
    user = User.find_by_email(params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
      sign_in user
      @history=user.histories.build(:TimeLogin => Time.now.strftime("%d/%m/%Y %H:%M"))
      @history.save
      redirect_back_or "/recalls"
    else
      flash.now[:error] = 'Invalid email/password combination'
      render 'new'
    end
  end

i am trying to save login time in my History model. this works fine at development environment. but when i add my work to heroku i get the following error in logs

2013-10-29T06:47:29.542675+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR:  null value in column "id" violates not-null constraint
2013-10-29T06:47:29.542675+00:00 app[web.1]: DETAIL:  Failing row contains (null, 2013-10-29 06:47:00, null, 1, 2013-10-29 06:47:29.533033, 2013-10-29 06:47:29.533033).
2013-10-29T06:47:29.542675+00:00 app[web.1]: : INSERT INTO "histories" ("TimeLogin", "TimeLogout", "created_at", "id", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6)):
2013-10-29T06:47:29.542675+00:00 app[web.1]:   app/controllers/sessions_controller.rb:11:in `create'

please guide me what i am doing wrong? i am unable to figure out because same works at my dev site Thanks in Advance

Was it helpful?

Solution

i fixed the issue by adding
set_primary_key :id to my model, as in migration i created id as SERIAL

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top