Forum: Ruby Create with console

027f88d17068dde230d0261d70bea262?d=identicon&s=25 Simon Eric (noumedem)
on 2014-06-11 18:12
Hello everybody

i want to create a data with the console on an model in db.

This is the model:

class CreateBancas < ActiveRecord::Migration
  def change
    create_table :bancas do |t|
      t.string :nome
      t.string :cognome
      t.integer :numero
      t.integer :scadenza
      t.integer :type

      t.timestamps
    end
  end
end

When i do an query like this:

Banca.create!(:nome => "eric", :cognome => "noumedem", :scadenza =>
"2016", :numero => "123", :type => "1")
 I have an error like so:


ActiveRecord::SubclassNotFound: Invalid single-table inheritance type: 1
is not a subclass of Banca
  from
/home/eric/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/inheritance.rb:178:in
`subclass_from_attrs'
  from
/home/eric/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/inheritance.rb:22:in
`new'
  from
/home/eric/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/validations.rb:39:in
`create!'
  from (irb):307
  from
/home/eric/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in
`start'
  from
/home/eric/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in
`start'
  from
/home/eric/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands.rb:62:in
`<top (required)>'
  from bin/rails:4:in `require'
  from bin/rails:4:in `<main>'


What is wrong here?

Thank you
027f88d17068dde230d0261d70bea262?d=identicon&s=25 Simon Eric (noumedem)
on 2014-06-11 18:33
I resolved a problem. Rails don't like calling an colunm "type"
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.