SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    NoMethod Error Simply Rails

    Hello,

    I am following along in Simply Rails 2 and have encountered an error I am unsure how to fix.

    On page 143 it tells us to execute the command "ruby script/server" and then check the web browser. Everything was perfect at this point and appeared just like the book.

    Then on page 146 it talks about scaffolding and tells us to execute the following command "ruby script/generate scaffold Story name:string link:string"

    At this point I did not get the results shown in the book. It asked if I wanted to replace the files and I chose "y".

    When I ran the "ruby script/server" command again, I got a strange screen on the console and on the browser. I have included screenshots for each of these.

    Can somebody please tell me what went wrong? Also, can you tell me how to get it back to normal.

    Thanks so very much!

    -New Ruby Learner
    Attached Images Attached Images

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,161
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    This mentioning of scaffolding in the book has caused problems for others too.
    We won’t be generating any permanent scaffolding in this project, but I do encourage you to experiment with this approach in your own projects, as there may be cases in which you’ll find it useful.
    The key word's are won't ... in this project and experiment ... your own projects.
    But the use of the word "permanent" and the inclusion of the example command line syntax (which uses a same ModelName and field:type-s) is misleading.

    Have you tried the "Destroy What You Create!" tip (pg. 147)?
    If you ever mess up a call to script/generate, you may find its alter ego script/destroy very helpful. This takes exactly the same arguments as script/generate but attempts to reverse what it did, removing newly generated files and modifications to existing files. You can think of the two scripts as the upand downmethods of a migration.
    I have never tried it, but the I think the syntax would be the same as the script/generate you used ("takes exactly the same arguments") except it would be script/destroy instead.

    If that doesn't work, you will need to go back to at least page 121. Although it would probably be best to delete the shovell directory, do "rails shovell" again to recreate the directory, CREATE 'stories' table again (pg. 102), and then go to page 121

    Personal Recommendation* If you want to learn about scaffolding try the "Step by Step" tutorial http://www.sitepoint.com/forums/show...3&postcount=41

  3. #3
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, tell me if I am understanding correctly...

    1)DELETE the entire "shovell" folder from "rails_apps"
    2)start over from scratch? i.e. follow the other instructions you gave.

    Thanks for the input! Learning new technologies is fun but incredibly frustrating. Makes you feel like an idiot :-(.

    I was confused by the book in that I am assuming everything in bold black is to be entered into the console. In certain parts of the book it is very descriptive in that it says "type this" and other places it is more vague as it is here.

    Thanks so much for the help!

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,161
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Yes, it can be very frustrating. Did you try the script/destroy ?
    I would only start from scratch as a last resort. Although I myself did so 3 times before I got through the entire book. Once I figured out that I should save a copy of the app directory after each chapter (as shovell_5. shovell_6, etc.) everything went OK and I didn't need to go back to the back-up copy of the last successful chapter (Murphy's Law ). But I suggest you save back-up copies periodically so you won't need to start from scratch if you run into problems again.

    EDIT:
    Just in case you didn't know, the code archive can be got here http://www.sitepoint.com/books/rails2/code.php
    And the known typos and errors are here http://www.sitepoint.com/books/rails2/errata.php

    I submitted a possible error for page 347 - my "rake test" showed
    14 tests, 16 assertions, 0 failures, 0 errors
    for the unit tests, not the book's
    15 tests, 17 assertions, 0 failures, 0 errors
    But as the errata page still doesn't show this, it might only be me.

  5. #5
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I tried it...didn't seem to do anything. I had to close the console and reopen because I couldn't figure out how to get back to a line that had >>....the console wouldn't allow me to type anything. Tried to use CTRL+d ...didn't work......" .quit" didn't work.

    I just deleted the whole folder.

    Not to sound stupid, but how do you suggest I make a backup? What I mean is, when I am running from the console, I guess I would just call it up "cd shovell_6" etc.?

    That makes sense. Thanks for the help. Thank God for sitepoint forums!

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,161
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    You could do that. But I would simply delete the app directory (or rename to shovell_buggy, if you want to look at it or try to debug it at some point) and copy the last good chapter (or whatever stage you save at, depends on how far back you want to go) renamed back to shovell and try again.

    For example, from my notes
    pg 121 GENERATE Story model:
    \shovell>ruby script/generate model Story name:string link:string
    pg 125 EDIT: test\fixtures\[03-]stories.yml *
    pg 129 EDIT: db\migrate\[05-]001_create_stories.rb *
    ~In my installation the migration file is YYYYMMDDhhmmss_create_stories.rb
    pg 131 MIGRATE:
    \shovell>rake db:migrate
    pg 133 CREATE records:
    \shovell>ruby script/console
    pg 135 VERIFY record entry:
    >> Story.find(:all)
    pg 138 ~I recommend that you do Not delete record
    pg 140 GENERATE Stories controller:
    \shovell>ruby script/generate controller Stories index
    pg 143 VERIFY controllers and views are working correctly:
    \shovell>ruby script/server
    open browser to:
    http://localhost:3000/stories
    pg 146 ~I recommend that you do Not generate scaffolding, quote "experiment with this
    approach in your own projects"
    ~I recommend trying the "Step by Step" tutorial instead.
    pg 149 EDIT: app\views\stories\[08-]index.html.erb
    pg 150 EDIT: app\controllers\[09-]stories_controller.rb
    EDIT: app\views\stories\[10-]index.html.erb
    pg 151 quote "In case you deleted all of your model records when we experimented
    with scaffolding earlier, make sure you create at least one story."
    EDIT: app\controllers\[11-]stories_controller.rb *
    EDIT: app\views\stories\[12-]index.html.erb *
    VERIFY:
    \shovell>ruby script/server
    open browser to:
    http://localhost:3000/stories
    pg 152 EDIT: app\views\stories\[13-]index.html.erb *
    EDIT: app\controllers\[16-]stories_controller.rb *
    VERIFY:
    \shovell>ruby script/server
    open browser to:
    http://localhost:3000/stories
    It might be a good idea to save copies after each VERIFY, eg.
    shovell_135
    shovell_143
    shovell_151
    shovell_152 (= shovell_5)

    So if I mess up on page 147 and I find out things are mucked up when I get to page 151, I can delete/rename shovell, copy shovell_143 to shovell, and restart from page 143.

    I guess a good rule would be if you ever find yourself thinking "boy that was a lot of work, I'm glad it's OK" then that would be a good time to save a copy.


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
  •