ruby on rails - NoMethodError in Student#categories -
showing /home/ns/school/app/views/student/_student_category_list.erb
line #4 raised:
undefined method `each' nil:nilclass
<ul id="category-list"> <% @student_categories.each |c| %> <li class="list<%=cycle('odd', 'even')%>"> <div class="category-name"><%= c.name %></div> <div class="category-edit"><%= link_to "#{t('edit_text')}", :url => { :action => 'category_edit', :id => c.id } %> </div> <div class="category-delete"><%= link_to "#{t('delete_text')}", :url => { :action => 'category_delete', :id => c.id } , :confirm =>"#{t('delete_confirm_msg')}"%> </div> </li> <% end %> </ul>
essentially, needs see controller code, because want ensure instance variable @student_categories contains hash of data.
however, can infer @student_categories either:
- not being initialized in controller @ all, result in error.
- not being initialized in correct controller action.
- is being misspelled @student_category/@student_categories someplace in code, (rails pluralization can confusing @ first.)
solution:
- check model named student_category.rb or student.rb
- check controller named student_categories_controller.rb or students.rb
since listing of categories, i'm going assume @student_categories variable found in index action, within student_categories_controller.rb in case student_category_list action.
adjust appropriately.
class studentcategoriescontroller < applicationcontroller def student_categories_list # action end end
you should have index action in controller, this:
def index @student_categories = studentcategory.all # not production end
or maybe, looks this:
def index @student_category = studentcategory.all # not production end
perhaps looks this:
def index @student_categories = student.all # not production end
with model, view, , controller code, give exact solution, 99% of time it's problem pluralization. rails has naming conventions should at.
also, careful using model.all in production, since there tens of thousands of records in model.
Comments
Post a Comment