0

I get an error when new creating a new class in a Rails Controller.

How can I understand what's happening here? Thanks

Error:
NoMethodError in MystudentsController#new

undefined method `attribute_method_matcher' for nil:NilClass  
Rails.root: E:/Nam 4 HK 1/TT CNPM/workspace/lab2

app/controllers/mystudents_controller.rb:27:in `new'
app/controllers/mystudents_controller.rb:27:in `new'

And this is function new in mystudent_controller.rb file:

def new    
  @mystudent = Mystudent.new
  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @mystudents }
  end
end
New Alexandria
  • 6,951
  • 4
  • 57
  • 77
Tri.Huynh
  • 3
  • 2
  • Mystudent seems to be nil (not defined) Can you please post your model and your controller in full length? – Noxx Sep 13 '12 at 20:35
  • 1
    Additionally, the line "format.xml { render :xml => @mystudents } " need to be changed to "@mystudent" instead of "@mystudents" – Noxx Sep 13 '12 at 20:41

2 Answers2

5

I believe that one of your column names in the table is a reserved word.
Look for typical things for a student, class, or something like that...
That would typically trigger this - `attribute_method_matcher'

Raghav
  • 2,128
  • 5
  • 27
  • 46
-1

You have a typo there. @mystudents needs to be @mystudent.

You're getting this error message because the variable @mystudents [sic] has never been assigned to and therefore is nil.

levinalex
  • 5,889
  • 2
  • 34
  • 48