javascript - getting error on destroy item -
i have 1 crud of project , trying destroy project list using ajax.
class projectscontroller < applicationcontroller . . . def destroy @project.destroy respond_to |format| format.js end end end
destroy.js
$('#all_projects').html("<%= escape_javascript render(:partial => 'projects/all_projects') %>");
all_projects.html.erb
<table> <thead> <tr> <th>name</th> <th>team size</th> <th colspan="3"></th> </tr> </thead> <tbody> <% @projects.each |project| %> <tr> <td><%= project.name %></td> <td><%= link_to 'show', project %></td> <td><%= link_to 'edit', edit_project_path(project) %></td> <td><%= link_to 'destroy', project, method: :delete, data: { confirm: 'are sure?' } ,:remote=>true%></td> </tr> <% end %> </tbody> </table>
index.html.erb
<h1>listing projects</h1> <div id="all_project"> <%= render 'projects/all_projects'%> </div>
when try load project working fine. when destroy project give me error in server side below.
actionview::template::error (undefined method `each' nil:nilclass): 9: </thead> 10: 11: <tbody> 12: <% @projects.each |project| %> 13: <tr> 14: <td><%= project.team_size %></td> app/views/projects/_all_projects.html.erb:12:in `_app_views_projects__all_projects_html_erb___3489379756657223366_70218666904220'
what missed please me find. thanks
this error because of missing object @project
details.
when put @projects = project.all
in destroy method error gone , function working fine.
Comments
Post a Comment