我正在尝试向我的模型添加删除功能。这是我想出的,但即使我不需要渲染页面来删除某些东西,Rails 也会渲染并且找不到“delete.html.erb”的文件
我正在使用 Ruby 2.0dev 和 Rails 4.0
我的删除链接:
<%= link_to "Delete", reservation_delete_path(item), :class => "btn btn-small btn-danger", method: :delete, data: {confirm: 'Are you sure?'} %></td>
我的路线文件:
match 'reservations/delete/:id' => 'reservations#delete', via: :delete, :as => 'reservation_delete'
我的控制器:
def delete
@current = Reservations.find(params[:id])
if current_user
if @current.user_id == current_user.id
@current.destroy!
redirect_to reservations_path
else
redirect_to reservations_path
end
else
redirect_to reservations_path
end
end