2011-12-30 27 views
1

錯誤:Rails錯誤:未定義的方法`attribute_methods_generated?'對於零:NilClass

undefined method `attribute_methods_generated?' for nil:NilClass 

的代碼是一個簡單的允許某人註冊。在控制器中創建@tutor對象。每當我刪除form_for,頁面加載罰款,但沒有別的似乎修復它。

代碼:

<% form_for(@tutor) do |f| %> 

<table class="form_table" id="home_form"> 
    <tr> 
     <td>First Name:</td> 
     <td class="form"> 
      <%= f.text_field :fname, :class => 'form', :size => 30 %> 
     </td> 
    </tr> 
    <tr> 
     <td>Last Name:</td> 
     <td class="form"> 
      <%= f.text_field :lname, :class => 'form', :size => 30 %> 
     </td> 
    </tr> 
    <tr> 
     <td>Email:</td> 
     <td class="form"> 
      <%= f.text_field :email, :class => 'form', :size => 30 %> 
     </td> 
    </tr> 
    <tr> 
     <td>Password:</td> 
     <td class="form"> 
      <%= f.password_field :password, :class => 'form', :size => 20 %> 
     </td> 
    </tr> 
] 
      <td>&nbsp;</td> 
    <td> 
     <div align="left"> 
      <%= f.hidden_field :branch_id, :value => @branch.id.to_s %> 
      <%= f.submit 'Submit', :class => 'submit', :style => 'margin-left:3px;' %> 
     </div> 
    </td> 
    </tr> 
</table> 
<% end %> 

這裏是堆棧跟蹤:

activesupport (3.0.10) lib/active_support/whiny_nil.rb:48:in `method_missing' 
activerecord (3.0.10) lib/active_record/attribute_methods.rb:51:in `respond_to?' 
actionpack (3.0.10) lib/action_view/helpers/form_helper.rb:329:in  `apply_form_for_options!' 
actionpack (3.0.10) lib/action_view/helpers/form_helper.rb:313:in `form_for' 
app/views/tutors/register.html.erb:3:in  `_app_views_tutors_register_html_erb__142383781_2257394860_0' 
actionpack (3.0.10) lib/action_view/template.rb:135:in `send' 
actionpack (3.0.10) lib/action_view/template.rb:135:in `render' 
activesupport (3.0.10) lib/active_support/notifications.rb:54:in `instrument' 
actionpack (3.0.10) lib/action_view/template.rb:127:in `render' 
actionpack (3.0.10) lib/action_view/render/rendering.rb:59:in `_render_template' 
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument' 
activesupport (3.0.10) lib/active_support/notifications/instrumenter.rb:21:in `instrument' 
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument' 
actionpack (3.0.10) lib/action_view/render/rendering.rb:56:in `_render_template' 
actionpack (3.0.10) lib/action_view/render/rendering.rb:26:in `render' 
actionpack (3.0.10) lib/abstract_controller/rendering.rb:115:in `_render_template' 
actionpack (3.0.10) lib/abstract_controller/rendering.rb:109:in `render_to_body' 
actionpack (3.0.10) lib/action_controller/metal/renderers.rb:47:in `render_to_body' 
actionpack (3.0.10) lib/action_controller/metal/compatibility.rb:55:in `render_to_body' 
actionpack (3.0.10) lib/abstract_controller/rendering.rb:102:in `render_to_string' 

這裏是家教類:

class Tutor < ActiveRecord::Base 
    belongs_to :branch 


end 
+1

你是否100%確定'@ tutor'不是形式中的零?這可能是爲什麼它這樣做。另外,你的代碼中有大約3/4的字符是隨機的']'字符。 – iwasrobbed 2011-12-30 02:48:20

+0

這個錯誤的堆棧跟蹤是什麼?我不知道它會如何發生。 – 2011-12-30 04:07:21

+0

我確定@tutor不是零。剛剛添加了上面的堆棧跟蹤。 – vramon 2011-12-30 23:56:31

回答

0

想通了。我把「class」作爲表中的一行。

感謝您的幫助!

相關問題