我无法在我的控制器中使用我的销毁操作来工作。我已经读过您必须包含要删除的默认JavaScript库,但我已经完成了(至少我认为我有),但它仍然无法正常工作。我的应用程序背景:文章是"食谱",所以我的控制器叫做recipes_controller。这是我的recipes_controller中的代码:
class RecipesController < ApplicationController
before_action :authenticate, except: [:index, :show]
before_action :set_recipe, only: [:show, :edit, :update, :destroy]
# GET /recipes
# GET /recipes.json
def index
@recipes = Recipe.all
end
# GET /recipes/1
# GET /recipes/1.json
def show
end
# DELETE /recipes/1
# DELETE /recipes/1.json
def destroy
@recipe.destroy
respond_to do |format|
format.html { redirect_to recipes_url, notice: 'Recipe was
successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_recipe
@recipe = Recipe.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def recipe_params
params.require(:recipe).permit(:title, :body, :published_at, :category_ids => [])
end
end
然后,这是我的application.html.erb文件的代码,我认为我已经包含了默认的javascript库:
<html>
<head>
<title>inherentlydope</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>d
<%= csrf_meta_tag %>
</head>
<body>
<%= content_tag :p, notice, :class => 'notice' if notice.present? %>
<%= content_tag :p, alert, :class => 'alert' if alert.present? %>
<%= yield %>
</body>
</html>
然后,这是我的routes.rb文件:
Rails.application.routes.draw do
root to: "recipes#index"
#resources :comments
resources :recipes do
resources :comments
end
resources :users
resource :session, only: [:new, :create, :destroy] #always deal with session, not sessionS
get '/login' => "sessions#new",as: "login"
get '/logout' => "sessions#destroy", as: "logout"
end