SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    According to Sitepoints Simply Rails 2 book

    I have been going through Sitepoints Simply Rails 2 book. I am at the part where I create a text file (I used Context) and save it as an .rb file. I did what the book says and saved it and tried to run the $ ruby filename.rb at the command prompt and I get the following error," 'ruby' is not recognized as an internal or external command, operable program or command." I am not sure what I am missing and the book doesn't really specify. I have tried to change the directory also and run it with no luck. Am I suppose to run this from the command line or the "Ruby" console window? If anyone can tell me what I am doing wrong/missing I would be greatly appreciative.

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have a $ command prompt that suggests you are using a UNIX based OS, such as one of the Linux distros or OS X. The "ruby filename.rb" form is for MS Windows. I believe that in a UNIX type environment you can drop the ruby and just enter "filename.rb" and the OS will sort out the appropriate executable mapping for you.

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried to remove the ruby and I received the same error message. Thanks

  4. #4
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are you typing the dollar sign? you shouldn't be, that IS the prompt. You should just be typing ' ruby filename.rb ' at your prompt. If that doesn't work you need to make sure you have ruby installed.

  5. #5
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't have the $ prompt. I am using windows XP and the command prompt window has the ">" sign for the prompt. I followed the instructions in the Simply Rails 2 book to download ruby so I am assuming that I am running ruby. Thank you for the suggestions. I will keep at it.

  6. #6
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try typing

    ruby -v

    which should show you which version of ruby you have installed.

  7. #7
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I typed the ruby -v and the same error message came up "ruby is not recognized as an internal or external command, operable program or batch file". I am going to try and download ruby again and try again. Is there any mirror site that has a current version of ruby? or is the a specific version of ruby I should be running? I downloaded the version that was listed in the book.

  8. #8
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to add the ruby bin folder to your PATH.

    For example, if Ruby is installed in c:\ruby, you need to add c:\ruby\bin to the path Environment variable. You can do this at the command line, but you'll probably find it easier to do it via the system properties (System icon in control panel). Click on the Advanced tab, and then click on the "Environment variables" button. In the lower pane, scroll down to the path entry and highlight it. Then click on edit. Add the ruby bin address to the end of the path using a semi-colon to separate it from the previous entry. So if your ruby bin folder is at c:\ruby\bin, you would add:
    Code:
    ;c:\ruby\bin
    To the end of the path. Make sure you don't delete any existing entries as this may stop other systems working. The easiest way to get to the end of the listing is to use the end key on your keyboard.

  9. #9
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Okay I added the following code to the end of my path listed in the previous thread. I can now pull up the ruby version in the command prompt but when I type in "ruby 01-car-classes.rb" I get the following error message "ruby No such file or directory --01-car-classes.rb (LoadError)

  10. #10
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I also tried to change the directory to where I saved my .rb files "C:\InstantRails\ruby\scripts\01-car-classes.rb" and I get a message window telling me that windows cannot open file, and it gives me the option to either use the Web service to find the appropriate program or select a program from a list. I clicked the Web service and it takes me to a microsoft help page that tells me nothing.

  11. #11
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you clarify something. Does this work:
    Code:
    ruby "C:\InstantRails\ruby\scripts\01-car-classes.rb"

  12. #12
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I typed in the command prompt
    The default setting is this
    C:\Documents and Settings\Administrator>cd ../.. (to change the directory)
    C:\>ruby C:\InstantRails\ruby\scripts\01-car-classes.rb (I hit enter and it took me back to)
    C:\> (Does this mean it worked?

    Here is the code that's in the 01-car-classes.rb file

    class Car
    @WHEELS = 4 # class constant
    @@number_of_cars = 0 # class variable
    def initialize
    @@number_of_cars = @@number_of_cars + 1
    end
    def self.count
    @@number_of_cars
    end
    def mileage=(x) # instance variable writer
    @mileage = x
    end
    def mileage # instance variable reader
    @mileage
    end
    end

    class StretchLimo < Car
    WHEELS = 6 # class constant
    @@televisions = 1 # class variable
    def turn_on_television
    # Invoke code for switching on on-board TV here
    end
    end

    class PontiacFirebird < Car
    end

    class VolksWagen < Car
    end

  13. #13
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I expect so. There is nothing in that code that would generate an output.

    Add this to the bottom of the file:
    Code:
    car = VolksWagon.new
    puts "My car is a #{car.class}"


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
  •