Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Migrations and Relationships Single Table Inheritance

Michael Baker
Michael Baker
5,709 Points

Error on a.type = "Customer"

when Hampton sets a = Account.first and then runs a.type = "Customer"

I get the error below.

irb(main):007:0> a.type = "Customer"
NoMethodError: undefined method `type=' for #<Account:0x007fb0688bb210>
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activemodel-4.2.1/lib/active_model/attribute_methods.rb:433:in `method_missing'
    from (irb):7
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in `start'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:9:in `start'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/MichaelBaker/treehouse/projects/biller/bin/rails:8:in `<top (required)>'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/commands/rails.rb:6:in `call'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/command_wrapper.rb:38:in `call'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:183:in `block in serve'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:156:in `fork'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:156:in `serve'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:131:in `block in run'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:125:in `loop'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:125:in `run'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'irb(main):008:0>

6 Answers

Oops, sorry for the misunderstanding.

Sounds like what you need to do is do a new migration called AddTypeToAccounts. Then in the migration file do

def change add_column :accounts, :type, :string

Try that and then run another rake db:migrate

Are you in irb or rails console? Rails console is what you want if you're dealing with the database.

That kind of an error usually means that it's not finding the "type" column in the Accounts table. Something may have happened with the migration. In your migration file for CreateAccounts, do you have t.string :type?

Michael Baker
Michael Baker
5,709 Points

Hi Amanda - thanks for your reply.

I believe I'm in the rails console - this is what I'm doing in terminal:

```Michaels-Air:biller MichaelBaker$ rails c

Loading development environment (Rails 4.2.1) irb(main):001:0> Customer.first

Customer Load (0.3ms) SELECT accounts.* FROM accounts ORDER BY accounts.id ASC LIMIT 1 => #<Customer id: 1, name: "Bob's Emporium", email: nil, about: nil, created_at: "2015-04-29 16:59:04", updated_at: "2015-04-29 16:59:04">

irb(main):002:0> a = Account.first

Account Load (0.4ms) SELECT accounts.* FROM accounts ORDER BY accounts.id ASC LIMIT 1 => #<Account id: 1, name: "Bob's Emporium", email: nil, about: nil, created_at: "2015-04-29 16:59:04", updated_at: "2015-04-29 16:59:04">

irb(main):003:0> a.type = "Customer"

NoMethodError: undefined method type=' for #<Account:0x007fb0658b6858> from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activemodel-4.2.1/lib/active_model/attribute_methods.rb:433:inmethod_missing' from (irb):3 from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in start' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:9:instart' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in console' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:inrun_command!' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in <top (required)>' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:inrequire' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in block in require' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:inload_dependency' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in require' from /Users/MichaelBaker/treehouse/projects/biller/bin/rails:8:in<top (required)>' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in load' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:inblock in load' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in load_dependency' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:inload' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/commands/rails.rb:6:in call' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/command_wrapper.rb:38:incall' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:183:in block in serve' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:156:infork' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:156:in serve' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:131:inblock in run' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:125:in loop' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application.rb:125:inrun' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.4/lib/spring/application/boot.rb:18:in <top (required)>' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /Users/MichaelBaker/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from -e:1:in<main>'irb(main):004:0>```

Michael Baker
Michael Baker
5,709 Points

When I first followed Hampton's steps, I had a typo and only had t.string rather than t.string :type. I've since added and done rake db:migrate.

Is it working for you now?

Michael Baker
Michael Baker
5,709 Points

no -I did that before posting the errors above.