SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem using .new - p101 Lenz

    Hi, this is the response I get when trying to create a new instance of the Story class, as per p101 of Patrick Lenz's book. It looks like something in my setup is screwy can anyone help me figure out what's wrong? Thank you! Zo

    >> class Story < ActiveRecord::Base; end
    => nil
    >> story = Story.new
    ActiveRecord::StatementInvalid: ActiveRecord::StatementInvalid
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/sqlite_adapter.rb:365:in `table_structure'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/core_ext/object/misc.rb:23:in `returning'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/sqlite_adapter.rb:364:in `table_structure'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/sqlite_adapter.rb:215:in `columns'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:763:in `columns'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2060:in `attributes_from_column_definition_without_lock'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/locking/optimistic.rb:45:in `attributes_from_column_definition'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1502:in `initialize_without_callbacks'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in `initialize'
    from (irb):2:in `new'
    from (irb):2

  2. #2
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have a sqlite-ruby gem installed? How about SQLite itself?

  3. #3
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah... I was attempting, clearly not very successfully, to use mysql. Any idea how I get ruby to use the mysql that I've installed?

  4. #4
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you configured your database.yml properly and created the schema you require?

  5. #5
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah. Durrrr. Yes, that turned out to be it –&#160;Ruby was still trying to use sqlite instead of mysql, as specified in the database.yml file. It's all working perfectly now.

    Thanks so much for your help Luke!

  6. #6
    SitePoint Member
    Join Date
    May 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would I configure the Database.yml file? I'm having the same error message....saying can not find stories Table.


    I must have overlooked a step but dont know which one.....I've been struggling with this all day long.

  7. #7
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Easy. database.yml is in the config folder. Open it with your text editor and replace 'sqlite' with 'mysql'. You may also have to set your database name.

  8. #8
    SitePoint Member
    Join Date
    May 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my database.yml file in the RailsApp >> Shovell >> Config>> Database.yml

    Where would I chage to Mysql...just in the adapter line ? Sorry for these nubish questions. i appreciate the help very much. thanks


    # SQLite version 3.x
    # gem install sqlite3-ruby (not necessary on OS X Leopard)
    development:
    adapter: sqlite3
    database: db/development.sqlite3
    timeout: 5000

    # Warning: The database defined as 'test' will be erased and
    # re-generated from your development database when you run 'rake'.
    # Do not set this db to the same as development or production.
    test:
    adapter: sqlite3
    database: db/test.sqlite3
    timeout: 5000

    production:
    adapter: sqlite3
    database: db/production.sqlite3
    timeout: 5000

  9. #9
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it would be
    Code:
    adapter: mysql
    database: shovell_development
    
    (no timeout)
    If you create your rails app with
    Code:
    rails shovell -d mysql
    It will generate the correct database.yml file. The change to sqlite happened in Rails 2.0.2
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.

  10. #10
    SitePoint Member
    Join Date
    May 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had rails 2.02 installed the first time, but when I encountered this problem, I thought it had to do with my version...I thought I read that some functionality are the same in 2.02 vs 1.86 so I deleted rails from my comp and reinstalled 1.86...I guess I shouldn't have donethat?.

    what should I do???? Delete my rails app and reinstall again with 2.02? and start all over? Starting over and getting to this point is pretty quick, but if I dont have to restart the install again, that would be great. Please let me know what I should do first? change my Database.yml file or reinstall?

    Sorry for the nubbish questions...I'm a graphic Designer wondering in the world of Scripting, with the hopes of being a Web Developer one day.

  11. #11
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, first of all, you're confusing ruby (1.8.6) with rails (2.0.2). They are two combined, but different things. Ruby is a language, just like PHP. Ruby on Rails (RoR, or just "rails") utilizes ruby and creates a framework on top of the language that gives your constructs and conventions, to help you program (a PHP example would be CakePHP, or Zend Framework).

    Second, to rebegin an application, you would not have to uninstall Rails, you would simple delete the shovell directory that you have created, and recreate it with the rails command.

    That said, you do not need to recreate your application, just fix your database.yml file, as that is the only location that rails uses to determine your database.

    Code:
    development:
      adapter: mysql
      database: cia_development
      host: localhost
      username: root
      password:
     	
     test:
      adapter: mysql
      database: cia_test
      host: localhost
      username: root
      password:
     	
      production:
        adapter: mysql
        database: cia_production
        host: localhost
        username: root
        password:
    Where cia should be changed to shovell in this case, since that is the name of your application
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.

  12. #12
    SitePoint Member
    Join Date
    May 2008
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the help guys.

    My solution was to delete the Shovell folder in the Railsapp folder and start fresh. But prior to me creating the mysql (before I typed in $mysql -u root) I opened up that Database.yml file and changed the necessary changes. Then proceeded on with the book.

    From reading page 91, it wasn't apparent to me and the original poster to do anything, but look at a file. Maybe that section should be more clearer



    Thanks again


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •