[英]Ruby on Rails uninitialized constant ParagraphsController
我一直在嘗試在Ruby on Rails應用程序中進行一些清理。 我發現我完全沒有必要使用Paragraph腳手架,因為數據只是以另一種形式呈現。 因此,我刪除了此Paragraph腳手架,添加了Paragraph模型和Controller,然后還將“資源段”添加回了我的路線。 現在我得到這個錯誤:
uninitialized constant ParagraphsController
以下是我擁有的文件的示例:
#controllers/paragraph_controller.rb
class ParagraphController < ApplicationController
def destroy
Paragraph.find(params[:id]).destroy
respond_to do |format|
format.html { redirect_to :back}
format.json { head :no_content }
end
end
end
。
#models/paragraph.rb
class Paragraph < ActiveRecord::Base
belongs_to :page
end
。
#db/migrate:
class CreateParagraphs < ActiveRecord::Migration
def change
create_table :paragraphs do |t|
t.integer :page_id
t.string :description
t.string :paragraph_type
t.timestamps
end
end
end
。
#config/routes.rb
Rails.application.routes.draw do
##removed unnecessary stuff
resources :paragraphs
end
我不明白為什么會收到此錯誤。 單擊此鏈接時會發生這種情況:
<%= link_to "<span class='glyphicon glyphicon-trash'></span>".html_safe, paragraph, method: :delete, class: "btn btn-xs btn-danger", title: "Delete paragraph" %>
它應該是ParagraphsController(復數),並且還要更改文件名。
您定義的ParagraphController
不帶's',而不是ParagraphsController
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.