0

I have attempted to use lynda.com video commands and got stuck in different phases. Please help

So I input

rails console

Then I input the following

irb(main):001:0> subject = Subject.create (:name => "Second Subject", :position =>2)

But I got this syntax error and I have no clue! Please help

SyntaxError: (irb):1: syntax error, unexpected =>, expecting ')'
subject = Subject.create (:name => "Second Subject", :position =>2)
                                  ^
(irb):1: syntax error, unexpected ',', expecting end-of-input
subject = Subject.create (:name => "Second Subject", :position =>2)
                                                    ^
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/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>'
irb(main):002:0> subject = Subject.create 
Mysql2::Error: Table 'simple_cms_development.subjects' doesn't exist: SHOW FULL FIELDS FROM `subjects`
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'simple_cms_development.subjects' doesn't exist: SHOW FULL FIELDS FROM `subjects`
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `query'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `block in execute'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:287:in `execute'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/mysql2_adapter.rb:222:in `execute'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:301:in `execute_and_free'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:462:in `columns'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/model_schema.rb:208:in `columns'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/model_schema.rb:249:in `column_defaults'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/locking/optimistic.rb:169:in `column_defaults'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/core.rb:171:in `initialize'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/inheritance.rb:27:in `new'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/inheritance.rb:27:in `new'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.2/lib/active_record/persistence.rb:36:in `create'
    from (irb):2
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
    from /Users/muhammedz786/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/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>'irb(main):003:0> 
3
  • 1
    Well for one your MySQL subjects table doesn't exist. Have you ran rake db:migrate? Commented Jan 7, 2014 at 19:18
  • No database table exists. Listen to Travis. Commented Jan 7, 2014 at 19:24
  • There are two error traces there. 1) Dont have space before parentheses. That will cause and error. 2) No table for the model. This will also cause an error. Commented Jan 7, 2014 at 20:43

3 Answers 3

1

You shouldn't put space before the parentheses

# Bad
subject = Subject.create (:name => "Second Subject", :position =>2)

# Good
subject = Subject.create(:name => "Second Subject", :position =>2)
Sign up to request clarification or add additional context in comments.

2 Comments

See comment on your question. But, you should remove that space before the parentheses, and run the outstanding migrations bundle exec rake db:migrate. Then restart the console and try again.
Or he could just type reload! into the console and it will work fine without having to restart it.
1

I don't think you need the comma because you closed the quotation and identified the positions.

Comments

1

As far as I can tell this is a result of not having either loaded the database schema or ran all the migrations on your application.

I get this from your stack trace which contains the following:

Mysql2::Error: Table 'simple_cms_development.subjects' doesn't exist: SHOW FULL FIELDS FROM subjects ActiveRecord::StatementInvalid: Mysql2::Error: Table 'simple_cms_development.subjects' doesn't exist: SHOW FULL FIELDS FROM subjects

This is shown earlier in the stack than the syntax error, which means that it very well could be the underlying root of your problem. With rails it is best not to assume that the very first thing it tells you is the problem at hand, but to check the stack.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.