SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error on trying initial project

    I'm trying out RoR for the first time. I've setup a application called wedding and in it I have created a model and controller for attendee. I have a db table attendees that has things like name, address, and phone which are all just varchar fields for now.

    I figure it's a simple little project.

    I can go to localhost:3000/attendee and I get the link for New Attendee. Ok, now when I click that link I get an error:

    You have a nil object when you didn't expect it!
    The error occured while evaluating nil.type_cast_code
    This is the code shown:
    Code:
    Extracted source (around line #4):
    
    1: <h1>New <%= @scaffold_singular_name %></h1>
    2: 
    3: <%= error_messages_for(@scaffold_singular_name) %>
    4: <%= form(@scaffold_singular_name, :action => "create#{@scaffold_suffix}") %>
    5: 
    6: <%= link_to "Back", :action => "list#{@scaffold_suffix}" %>
    Ok, so I tried to put in a record in the db and go back to the listing page. I get the same error with different code.

    Code:
    Extracted source (around line #15):
    
    12:   <% for column in @scaffold_class.content_columns %>
    13:     <td><%= entry.send(column.name) %></td>
    14:   <% end %>
    15:     <td><%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => entry %></td>
    16:     <td><%= link_to "Edit", :action => "edit#{@scaffold_suffix}", :id => entry %></td>
    17:     <td><%= link_to "Destroy", {:action => "destroy#{@scaffold_suffix}", :id => entry}, {:confirm => "Are you sure?"} %></td>
    18:   </tr>
    Ok, so can anyone explain what's up with this? The code for the controller is just:
    Code:
    class AttendeeController < ApplicationController
    	model :attendee
    	scaffold :attendee
    end
    This is just like every demo I can find out there.

    I appreciate any help I can get.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  2. #2
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't really use scaffolrd but try:

    scaffold: attendees

  3. #3
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found out the problem was I didn't have an ID field in the db and I used a capital letter for the names of the fields. Once I fixed this it started to work.

    Of course after that I tried to run ruby scipt/generate scaffold attendee and I get an error:
    error Before updating scaffolding from new DB schema, try creating a table for your model (Attendee)

    Oh well, next hurdle.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by deuce868
    I found out the problem was I didn't have an ID field in the db and I used a capital letter for the names of the fields. Once I fixed this it started to work.

    Of course after that I tried to run ruby scipt/generate scaffold attendee and I get an error:
    error Before updating scaffolding from new DB schema, try creating a table for your model (Attendee)

    Oh well, next hurdle.
    Just for a future note, if you wished, for example the "name" to be the primary key, you must do something like this:
    Code:
     class Person < ActiveRecord::Base
     	self.primary_key = 'name'
     end
    I recently had a plethora of problems because I meant for my primary key to be 'name' but I assumed rails would know that it was the primary key.

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Yakima WA.
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the current gem version of rails when you run:

    ruby scipt/generate scaffold attendee

    It will fail. There is a bug that is fixed in the edge rails and will be there in a gem release soon. The workaround for now is to specify the model and the controiller to the scaffold command. Like so:

    ruby scipt/generate scaffold Attendee Attendee

    That will work for you for now.

    Cheers

    -Ezra


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
  •