Forum: Rails-ES no crea registro

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Da0cb14b3966fa76454c6f95dc1cb04e?d=identicon&s=25 Angel Mauricio Pino Gonzalez (Guest)
on 2007-02-07 04:20
(Received via mailing list)
agregue los isguiente al modelo de una relaciĆ³n en que use belongs_to
y no crea registros.
estoy usando sqlserver

MODELOS
Comuna
class Comuna < ActiveRecord::Base
  belongs_to :region
  validates_associated :region
  validates_presence_of :nombre

  def region
    Region.find(region_id).nombre
  end
end

Region
class Region < ActiveRecord::Base
  has_many :comunas
end

el log da esto al tratar de crear una nueva comuna:


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:26) [POST]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"commit"=>"Save", "action"=>"create",
"controller"=>"comunas", "comuna"=>{"nombre"=>"PARINACOTA",
"region_id"=>"1"}}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
  Region Load (0.000000)   SELECT TOP 1 * FROM
regiones WHERE (regiones.id = 1) 
  Region Columns (0.015000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('regiones', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('regiones'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'regiones'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.04700 (21 reqs/sec) | DB: 0.01500 (31%) | 302 Found
[http://localhost/comunas/create]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:28) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.04700 (21 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:29) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.06200 (16 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:31) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.015000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.03100 (32 reqs/sec) | DB: 0.01500 (48%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:32) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.06300 (15 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:34) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.016000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.04700 (21 reqs/sec) | DB: 0.01600 (34%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:36) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.15600 (6 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:37) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.04700 (21 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:39) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.04700 (21 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:40) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.06200 (16 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:41) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.07800 (12 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:42) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.016000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.01600 (62 reqs/sec) | DB: 0.01600 (100%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:44) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.09400 (10 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:45) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.06200 (16 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:46) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.04600 (21 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:48) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.047000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.04700 (21 reqs/sec) | DB: 0.04700 (100%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:49) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.07800 (12 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:51) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.04700 (21 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:53) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.07900 (12 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:54) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.06300 (15 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Processing ComunasController#create (for 127.0.0.1 at 2007-02-07
00:14:56) [GET]
  Session ID: 1b6f061bbd076b2e4465facc58b04ced
  Parameters: {"action"=>"create", "controller"=>"comunas",
"comuna"=>"new"}
  Comuna Columns (0.000000)   SELECT COLUMN_NAME as
ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType,
IS_NULLABLE As IsNullable, COL_LENGTH('comunas', COLUMN_NAME) as
Length, COLUMNPROPERTY(OBJECT_ID('comunas'), COLUMN_NAME,
'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'comunas'
Redirected to http://localhost:3000/comunas/create?comuna=new
Completed in 0.04700 (21 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://localhost/comunas/create?comuna=new]


Y no crea nada, alguna idea, gracias.
--
Angel Mauricio Pino G
AngelMauricio.PinoGonzalez@gmail.com
Movil: 08-577.92.72
Ffd012d72e7f61639724878825ed25a3?d=identicon&s=25 Damian Janowski (djanowski)
on 2007-02-07 04:54
(Received via mailing list)
On 2/7/07, Angel Mauricio Pino Gonzalez
<angelmauricio.pinogonzalez@gmail.com> wrote:
>
>         def region
>                 Region.find(region_id).nombre
>         end
> end

debe ser:

> class Comuna < ActiveRecord::Base
>         belongs_to :region
>         validates_presence_of :region_id
>         validates_presence_of :nombre
> end

y listo

fijate si anda
This topic is locked and can not be replied to.