SitePoint Sponsor

User Tag List

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

    Modifying the Controller, Cahpter 6

    On page 161 of the SimplyRails2 book, when I add this line:

    [def new
    @story = Story.new
    end]

    to the app/controllers/stories_controller.rb file, I get this error message in my browser:

    [NameError in Stories#new
    Showing app/views/stories/new.rhtml where line #4 raised:
    `@#<Story:0x2449268>' is not allowed as an instance variable name
    Extracted source (around line #4):
    1: <% form_for @story do |f| %>
    2: <p>
    3: namebr />
    4: <%= f.text_field :name %>
    5: </p>
    6: <p>
    7: linkbr /> ]

    If I don't add this line, I can see the form in the browser (but I assume it isn't set up to populate entries).

    I feel like when I was screwing around with scaffolding, I screwed something up.

    Any help would be appreciated!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,169
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Hi jakerockwell, welcome to the forums,

    From page 151
    In case you deleted all of your model records when we experimented
    with scaffolding earlier, make sure you create at least one story.
    Did you?

    Does your config/routes.rb file have
    Code Ruby:
      # Sample resource route (maps HTTP verbs to controller actions automatically):
      #   map.resources :products
      map.resources :stories

  3. #3
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mittineague, thx for the response!

    Im in the process of rereading everything carefully. I also updated Ruby, SQLlite, RubyGems, and Mongrel. (I had skipped over this the first time around). I cant believe I got as far as I did just by plugging away. Ill get back to this point soon, and hopefully I will have resolved the problem by then.

    In the meantime, I have another question. When we generate a model (page 122), it's supposed to create the migration file: db/migrate/001_create_stories.rb.

    Since this is the first migration file, shouldn't it always be numbered 001?

    Mine is numbered 20090604001419! Is this OK?

    Here it is-

    JakesMacBook:~ j$ cd shovell
    JakesMacBook:shovell j$ ruby script/generate model Story name:string link:string
    exists app/models/
    exists test/unit/
    exists test/fixtures/
    create app/models/story.rb
    create test/unit/story_test.rb
    create test/fixtures/stories.yml
    create db/migrate
    create db/migrate/20090604001419_create_stories.rb
    Last edited by jakerockwell; Jun 4, 2009 at 18:50.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,169
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Sometime after the book was written, Rails changed the migration file naming from sequential numbers to date time. i.e. YYYYMMDDHHMMSS

    They should still work the same and AFAIK even having both types at the same time works.

    If you starting over again I recommend not doing the scaffolding in the shovell app. If you want to try scaffolding try it in a different app instead and save yourself some troubles.

  5. #5
    SitePoint Member kellogg9's Avatar
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    Sometime after the book was written, Rails changed the migration file naming from sequential numbers to date time. i.e. YYYYMMDDHHMMSS

    They should still work the same and AFAIK even having both types at the same time works.

    If you starting over again I recommend not doing the scaffolding in the shovell app. If you want to try scaffolding try it in a different app instead and save yourself some troubles.
    very good points

  6. #6
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mittineague - Original problem from this thread has been resolved. Very much on track now. Thx for the help.


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
  •