Skip to content

Instantly share code, notes, and snippets.

@andrewhl
Created March 25, 2012 02:50
Show Gist options
  • Save andrewhl/2190915 to your computer and use it in GitHub Desktop.
Save andrewhl/2190915 to your computer and use it in GitHub Desktop.
<tr>
<td><%= f.label :first_name %></td>
<td><%= f.text_field :first_name %></td>
<td><%= f.label :last_name %></td>
<td><%= f.text_field :last_name %></td>
</tr>
<tr>
<td><%= f.label :health_card %></td>
<td><%= f.text_field :health_card %></td>
<td><%= f.label :medical %></td>
<td><%= f.text_field :medical %></td>
</tr>
<tr>
<td><%= f.label :grade %></td>
<td><%= f.text_field :grade %></td>
<td><%= f.label :class %></td>
<td><%= f.text_field :class %></td>
</tr>
<tr>
<td><%= f.label :campus %></td>
<td><%= f.text_field :campus %></td>
<td></td>
<td></td>
</tr>
<tr>
<td><%= f.label :emergency_first_name %></td>
<td><%= f.text_field :emergency_first_name %></td>
<td><%= f.label :emergency_last_name %></td>
<td><%= f.text_field :emergency_last_name %></td>
</tr>
<tr>
<td><%= f.label :emergency_phone %></td>
<td><%= f.text_field :emergency_phone %></td>
<td><%= f.label :shoe_size %></td>
<td><%= f.text_field :shoe_size %></td>
</tr>
class Child < ActiveRecord::Base
belongs_to :user
attr_accessible :first_name,
:last_name,
:health_card,
:medical,
:grade,
:class,
:campus,
:emergency_first_name,
:emergency_last_name,
:emergency_phone,
:shoe_size
end
class ChildrenController < ApplicationController
def new
@child = Child.new
end
def create
@child = Child.new(params[:child])
if @child.save
flash[:success] = "Your child was entered into the system successfully."
redirect_to new_child_path
else
render 'new'
end
end
end
Started GET "/children/new" for 127.0.0.1 at 2012-03-24 22:47:09 -0400
Processing by ChildrenController#new as HTML
Completed 500 Internal Server Error in 34ms
NoMethodError (undefined method `attribute_method_matcher' for nil:NilClass):
app/controllers/children_controller.rb:4:in `new'
app/controllers/children_controller.rb:4:in `new'
<% provide(:title, 'Register children') %>
<h2>Register your children</h2>
<%= form_for(@child) do |f| %>
<table>
<%= render 'fields', f: f %>
<div class="actions">
<%= f.submit "Register new child" %>
</div>
<% end %>
</table>
# Excerpted from schema
create_table "children", :force => true do |t|
t.string "first_name"
t.string "last_name"
t.string "health_card"
t.string "grade"
t.string "class"
t.string "campus"
t.string "shoe_size"
t.string "emergency_first_name"
t.string "emergency_last_name"
t.string "emergency_phone"
t.integer "parent_id"
t.text "medical"
t.text "pickup_info"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
@drewinglis
Copy link

How did you end up resolving this? I'm getting the same error. =(

@andrewhl
Copy link
Author

Oh yeah, I remember this. My problem was I'd named a field "class", which conflicts with the Ruby keyword "class". I had to rename it to child_class or something along those lines.

@drewinglis
Copy link

drewinglis commented Jun 27, 2012 via email

@drriley
Copy link

drriley commented Jul 2, 2012

Hello I am having this same issue I scaffold and everyting and when I try to run my New form I get this error. So the solution is just to change the field class?

@drewinglis
Copy link

drewinglis commented Jul 2, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment