SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simply rails 2- still need some feedback on page 105

    I am still trying to do the the practice exercise on page 105. I am using the the shovell prompt then I enter... class Author < ActiveRecord::Base, and it comes back that the syntax in incorrect. what am I doing wrong?

  2. #2
    SitePoint Zealot phillipus_rex's Avatar
    Join Date
    Jan 2007
    Location
    Silicon Holler
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 4877 View Post
    I am still trying to do the the practice exercise on page 105. I am using the the shovell prompt then I enter... class Author < ActiveRecord::Base, and it comes back that the syntax in incorrect. what am I doing wrong?
    The correct syntax is this:

    Code:
    class Author < ActiveRecord::Base; end
    If you leave off the semicolon and the "end" statement while building a class definition from the prompt, than you could receive a syntax error.
    "Be kind, for everyone you meet is fighting a
    hard battle." -Plato

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I pasted what you sent me into the shovell prompt and it said syntax is incorrect still, any idea why?

  4. #4
    SitePoint Zealot phillipus_rex's Avatar
    Join Date
    Jan 2007
    Location
    Silicon Holler
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Type this first, then try the command again:

    Code:
    ruby script/console
    Wait until the development environment loads before you try to type in the previous command.

    To exit the development environment and go back into the "shovell" directory, just type "exit".
    "Be kind, for everyone you meet is fighting a
    hard battle." -Plato

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that worked, but the syntax that is given in the book didn't work even when I put a semi colon after the the word weblog. the book says enter this...
    class Author < ActiveRecord::Base
    has_one :weblog
    end
    what do you make of this?

  6. #6
    SitePoint Zealot phillipus_rex's Avatar
    Join Date
    Jan 2007
    Location
    Silicon Holler
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 4877 View Post
    that worked, but the syntax that is given in the book didn't work even when I put a semi colon after the the word weblog. the book says enter this...
    class Author < ActiveRecord::Base
    has_one :weblog
    end
    what do you make of this?
    It looks like the author is just trying to get you to practice using the Rails console environment.

    The code should work as long as you are in the Rails console - which you get by typing:
    Code:
    ruby script/console
    If you are not in this console, than you will get syntax errors.

    When you are actually building a Rails app, you won't build your models from within the console anyway - you will always have a file that your model resides in. The only thing you'll run from the console is the "ruby script/generate model" command. This will automatically create a file within the "Models" directory that will contain the class and allow you to make modifications to that file and add associations like "has_one", "belongs_to", etc.

    I wouldn't let yourself get hung up on this if it's giving you problems. Sometimes the best thing to do is go on to the next section. To me, working with the files that are generated for you is a lot easier than trying to build models from within the console - maybe things will click better for you if you look ahead a little further. You can always come back to that section later.
    "Be kind, for everyone you meet is fighting a
    hard battle." -Plato


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
  •