SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Member The_Big_K's Avatar
    Join Date
    May 2008
    Location
    In my home
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Problem with entering rails environment with ruby script/console command

    Hello,

    I'm learning ruby from Patrick Lenz's "Build your Ruby On Rails Applications". Please help me with the following -

    I'm trying to do the following (copy-paste from book)

    To enter a Rails console, change to your shovell folder, and enter the command
    ruby script/console, as shown below. The >> prompt is ready to accept your
    commands:
    $ cd shovell
    $ ruby script/console
    Loading development environment.
    >>
    Please answer -

    1. Where exactly is 'shovell' folder located?
    2. I'm getting "ruby - no such file or directory -- script/console (LoadError)

    What am I doing wrong?

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,332
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    K,
    Note that the instructions indicate you should "change to your shovell folder"
    There was an earlier instruction (it has been quite a while since I went through that book - I don't remember well enough to guide you more specifically), maybe in a previous chapter, to create a folder for your project (shovell).
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Member The_Big_K's Avatar
    Join Date
    May 2008
    Location
    In my home
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ParkinT,

    Thanks for your response. I did create 'shovell' folder at specified location. I guess I haven't installed rails properly. I'll check & get back to you.

    Thanks

  4. #4
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you create a 'shovell' folder by running rails shovell ?

    Because that is what needed to happen.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  5. #5
    SitePoint Member The_Big_K's Avatar
    Join Date
    May 2008
    Location
    In my home
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm a dumba$$!

    There was some problem in my Rails installation. I reinstalled everything and it worked like magic.

    Thanks for your replies, everyone!

  6. #6
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,332
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by The_Big_K View Post
    I'm a dumba$$!
    No, you are not.


    "Experience is a cruel teacher; The test comes before the lesson"
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  7. #7
    SitePoint Member The_Big_K's Avatar
    Join Date
    May 2008
    Location
    In my home
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face

    aha! Thanks

    Now here's a ('serious') error -

    I'm using instant rails and everything's (servers) up and running!

    I've created the databases as per the instructions in the Patrick Lenz's book. I'm in the rails console. Right now, I'm following instructions on Page # 101 (from the ebook)

    Here's the error I'm getting while trying to create instance of the class 'Story'.

    Code Ruby:
    >> class Story < ActiveRecord::Base;end
    => nil
    >> story = Story.new
    ActiveRecord::StatementInvalid: Could not find table 'stories'
            from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
    active_record/connection_adapters/sqlite3_adapter.rb:29:in `table_structure'
            from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib
    /active_support/core_ext/object/misc.rb:28:in `returning'
            from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
    active_record/connection_adapters/sqlite3_adapter.rb:28:in `table_structure'
            from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
    active_record/connection_adapters/sqlite_adapter.rb:189:in `columns'
            from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
    active_record/base.rb:1080:in `columns'
            from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
    active_record/base.rb:2363:in `attributes_from_column_definition_without_lock'
            from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
    active_record/locking/optimistic.rb:55:in `attributes_from_column_definition'
            from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
    active_record/base.rb:1922:in `initialize'
            from (irb):6:in `new'
            from (irb):6
    >>

    Please note that I've created the table 'stories' as per following instructions and verified it from the phpMyAdmin:

    Code SQL:
    USE shovell_development;
    CREATE TABLE `stories` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) DEFAULT NULL,
    `link` VARCHAR(255) DEFAULT NULL,
    PRIMARY KEY (`id`)
    );

    Can anyone explain why am I not able to create an instance of the class Story?

  8. #8
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,332
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Are you running SQLLite or MySQL?
    It looksl like your database.yml is referencing SQLLite3 (in the 'development' section)
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  9. #9
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Creating the table via PHPMyAdmin is an odd way of doing this in the Rails world (the author probably used PHP before Rails). Usually you just leave database.yml as is (using SQLite) and start creating migrations. You run this code in the console:

    Code:
    script/generate model story name:string link:string
    It generates a model Story plus migration which sets up the table. You can apply this migration to your database by running:

    Code:
    rake db:migrate
    If you are following along with the book it's probably better to use their methods, but remember that there are simpler ways to achieve this for your own applications.

  10. #10
    SitePoint Member The_Big_K's Avatar
    Join Date
    May 2008
    Location
    In my home
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @ ParkinT: I'm using MYSQL. I guessed that too.

    @Fenrir2 : Could you please explain what does the code do? Looks to me that the code will migrate my current db to mysql (I'm sorry, if this it totally out of context).

  11. #11
    SitePoint Member The_Big_K's Avatar
    Join Date
    May 2008
    Location
    In my home
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Update:

    I ran the commands mentioned by Fenrir2. I checked the database.yml and it was using sqlite3.

    So, I'd like to know what magic did we do with

    script/generate model story name:string link:string

    and rake db:migrate

  12. #12
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You know what this command does:

    Code:
    script/generate model story
    It generates app/models/story.rb, and empty model file. If you add pairs of field:type the generator will produce a migration for your model. A migration is a script that adds/removes/changes tables in the database.

    Code:
    script/generate model story name:string link:string
    This command generates app/models/story.rb plus a migration which creates the table stories, with two colums: name, which is a string (varchar) and link (also a string). The id:integer column is generated automatically.

    Now you have a migration, but the changes haven't been applied to the database yet. The migration is just a script that makes the changes. You can run this migration by executing this command:

    Code:
    rake db:migrate
    So now the migration script runs, which executes SQL which creates the stories table with id, name and link columns.

    You can view the migration file (it's a Ruby script) in db/migrate/the-migration.rb. You can also write your own migrations. Here's more information: http://wiki.rubyonrails.org/rails/pa...dingMigrations

  13. #13
    SitePoint Member The_Big_K's Avatar
    Join Date
    May 2008
    Location
    In my home
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool!

    Thanks a lot!

  14. #14
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The author of the book will use db mibgrations in the next chapters, but Id like to know why the books example doesnt work., since im having the same issues.

  15. #15
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KenA View Post
    The author of the book will use db mibgrations in the next chapters, but I&#180;d like to know why the book&#180;s example doesn&#180;t work., since i&#180;m having the same issues.
    Same here. Following the bouncing ball on pages 102-3 with an InstantRails install does not seem to work. Something to do with the SQLite connector?

  16. #16
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but why does the following code

    story = Story.new

    gives this error
    "story = Story.new" RoRActiveRecord::StatementInvalid: Could not find table 'stories'

    when there exists a database table stories inside development, test and production databases that I have created according to book specifications.

    it's sort of a stupid error
    @deel $hahid

  17. #17
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Spiracle View Post
    Something to do with the SQLite connector?
    I think this may be the cause of the problem. It sounds like the default Rails or InstantRails configuration is using SQLite rather than MySQL. Therefore, you are setting up a MySQL database to work with your application, but the application is pointing at a SQLite database.

    Migration will work, because that will use the database prescribed in the database.yml. But manual set up will only work if you use the right database.

    I expect you need to modify your database.yml to use the MySQL database. Have a look at the book's source code and compare your file to the one in the source code.

  18. #18
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have tried both configurations Mysql and SqlLite3 but the thing is i keep getting the same error.
    @deel $hahid

  19. #19
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have you installed the mysql gem?
    your brain reacts in the same way whether you are
    looking at something or thinking about it...


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
  •