我不知道我的应用程序发生了什么。我有一些控制器工作正常,但这不是。
我的sylabus_controller.rb
# encoding: utf-8
module Admin
class SylabusController < BaseController
def destroy
@sylabu = @topic.sylabus.find(params[:sylabus])
@sylabu.destroy
redirect_to admin_course_topic_sylabu_path(@course, @topic), notice: 'Sylabus deleted'
end
我的/views/admin/sylabus/index.html.rb
<% @sylabu.each do |syla| %>
<tr>
<td><%= syla.mupet_code %></td>
<td><%= syla.name %></td>
<td style="width:155px">
<%= link_to '<i class="icon-pencil"></i>'.html_safe, edit_admin_course_topic_sylabus_path(@course,
@topic,
syla),
class: 'btn' %>
<%= link_to '<i class="icon-trash icon-white"></i>'.html_safe, [:admin, @course, @topic, syla], class: 'btn btn-danger', method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to '<i class="icon-eye-open"></i>'.html_safe, [:admin, @course, @topic, syla],
class: 'btn' %>
</td>
</tr>
<% end %>
目标网络在按钮删除是localhost:3000 / admin / courses / 1 / topics / 2 / sylabus.8并带有以下错误消息
Routing Error
No route matches [DELETE] "/admin/courses/1/topics/2/sylabus.8"
Try running rake routes for more information on available routes.
如果我从我的控制台执行rake路线
POST /admin/courses/:course_id/topics/:topic_id/sylabus(.:format) admin/sylabus#create
new_admin_course_topic_sylabu GET /admin/courses/:course_id/topics/:topic_id/sylabus/new(.:format) admin/sylabus#new
edit_admin_course_topic_sylabu GET /admin/courses/:course_id/topics/:topic_id/sylabus/:id/edit(.:format) admin/sylabus#edit
admin_course_topic_sylabu GET /admin/courses/:course_id/topics/:topic_id/sylabus/:id(.:format) admin/sylabus#show
PUT /admin/courses/:course_id/topics/:topic_id/sylabus/:id(.:format) admin/sylabus#update
DELETE /admin/courses/:course_id/topics/:topic_id/sylabus/:id(.:format) admin/sylabus#destroy
真诚地,我不知道错误即将发生,因为它是来自其他控制器的复制和粘贴功能完美。
非常感谢你的回答。
度过美好的一天
答案 0 :(得分:1)
通过.8
后缀,它看起来像是使用index
路径而不是delete
路径。尝试明确
<%= link_to 'blah'.html_safe, admin_course_topic_sylabus_path(:admin, @course, @topic, syla), method: :delete %>