Hi I''m very new to Ruby on Rails. I''ve tried to create a very
simple
test application on postgres database. I''ve installed
gem install postgres-pr
driver. My database table name is players. My model file in ruby is
named player.rb
when I go to
http://localhost:3000/players/list
I can see the list of the table
when I want to add new record
http://localhost:3000/players/new
I''m receiving this error :
 RuntimeError: ERROR  C55000  Mcurrval of sequence "players_id_seq" is
not yet defined in this session  Fsequence.c  L639  Rcurrval_oid: SELECT
currval(''players_id_seq'')
I know this is error from database. When I tired to do
SELECT currval(''players_id_seq'') on database i''ve
received the same
error. After nextval (''playe....'') and than SELECT
currval(''players_id_seq'') currval returned  good value.
I really want to stay on postgres database. Do any1 know what is wrong
or how to fix this when i want to use ActiveRecord for adding new
records to the database ?
Many thanks ...
btw : editing of the record is working fine too
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Try this SQL, it might work.  It resets the sequence number in a
table.  Can be obviously modified to work on any table with a regular
unique non-null incrementing primary-key ''id''
SELECT setval(''players_id_seq'', (SELECT MAX(id) FROM
players)+1);
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Strictly speaking, you not need the "+1", as nextval() will increment it. The "+1" will actually create a hole in the sequence - which of course may or may not be if importance to your application. 16 nov 2007 kl. 15.55 skrev fredistic:> SELECT setval(''players_id_seq'', (SELECT MAX(id) FROM players)+1);--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thanks,
i made it like this.
class PlayersController < ApplicationController
  scaffold:player
  def initialize
    super
    sql = ActiveRecord::Base.connection();
    sql.begin_db_transaction
    sql.execute("SELECT setval(''players_id_seq'', (SELECT
MAX(id) FROM
players));");
    sql.commit_db_transaction
  end
  def list
    @players=Player.find_all
  end
end
if it''s not entirely correct let me know plz.
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
have you created an sequencer ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jozef Neuschl wrote:> have you created an sequencer ?Indeed. It sounds like the id column is defined as an integer instead of a serial. -- Roderick van Domburg http://www.nedforce.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---