uninitialized constant Section ::编辑Ruby on Rails

时间:2014-12-07 06:50:32

标签: ruby-on-rails ruby ruby-on-rails-4

我试图摧毁一条记录,并且在尝试“销毁”时遇到以下错误:\ n记录:

NameError in SectionsController#destroy
uninitialized constant Section::Editor

Extracted source (around line #58):

    def destroy
      @section = Section.find(params[:id]).destroy
      flash[:notice] = "Section destroyed successfully."
      redirect_to(:action => 'index', :sheet_id => @sheet.id)
    end

Rails.root: /Users/test/Sites/permit

Application Trace | Framework Trace | Full Trace
app/controllers/sections_controller.rb:58:in `destroy'

sections_controler.rb:

class SectionsController< ApplicationController中

  layout "section"

  before_action :confirm_logged_in
  before_action :find_sheet
  before_filter :disable_content_type

    def index
      @sections = @sheet.sections.sorted
    end

    def show
      @section = Section.find(params[:id])
    end

    def new
      @section = Section.new({:sheet_id => @sheet.id, :name => "Default"})
      @sheets = @sheet.project.sheets.sorted
      @section_count = Section.count + 1
    end

    def create
      @section = Section.new(section_params)
      if @section.save
        flash[:notice] = "Section created successfully."
        redirect_to(:action => 'index', :sheet_id => @sheet.id)
      else
        @sheets = @sheet.project.sheets.sorted
        @section_count = Section.count + 1
        render('new')
      end
    end

    def edit
      @section = Section.find(params[:id])
      @sheets = @sheet.project.sheets.sorted
      @section_count = Section.count
    end

    def update
      @section = Section.find(params[:id])
      if @section.update_attributes(section_params)
        flash[:notice] = "Section updated successfully."
        redirect_to(:action => 'show', :id => @section.id, :sheet_id => @sheet.id)
      else
        @sheets = @sheet.project.sheets.sorted
        @section_count = Section.count
        render('edit')
      end
    end

    def delete
      @section = Section.find(params[:id])
    end

    def destroy
    if  @section = Section.find(params[:id]).destroy
      flash[:notice] = "Section destroyed successfully."
      redirect_to(:action => 'index', :sheet_id => @sheet.id)
    else
      flash[:notice] = "Crap, this is really not working"
    end
    end

       private

def section_params
  params.require(:section).permit(:sheet_id, :name, :position, :visible, :content_type, :content)
end

def find_sheet
  if params[:sheet_id]
    @sheet = Sheet.find(params[:sheet_id])
  end
end

  def disable_content_type
    if @content_type = "PDF"
      @disable_vdrop = true
      @disable_text = true
    elsif @content_type = "text"
      @disable_pdf = true
      @disable_vdrop = true
    else
      @disable_pdf = true
      @disable_text = true
    end
  end

end

奇怪的是,如果我删除" .destroy"它能够找到显示通知的部分。我试着做一个" if,else"声明说:

  def destroy
    if  @section = Section.find(params[:id])
      flash[:notice] = "Section destroyed successfully."
      redirect_to(:action => 'index', :sheet_id => @sheet.id)
    else
      flash[:notice] = "This is really not working"
    end
   end

它闪现的"部分被成功销毁。"

我的routes.rb包含:

  root "public#index"

  get 'show/:permalink', :to => 'public#show'
  get 'admin', :to => "access#index"

  resources :calculator

  match ':controller(/:action(/:id))', :via => [:get, :post]

非常感谢任何帮助!!

更新:已添加SECTIONS.HTML.ERB模板

<!DOCTYPE html>
<html>
  <head>
    <%= stylesheet_link_tag('application', :media => 'all') %>
  </head>
    </div>
 <%= render "access/loggedinheader" %>
  <body>
    <div id="main">
      <% if !flash[:notice].blank? %>
        <div class="notice">
          <%= flash[:notice] %>
        </div>
      <% end %>
    <div id="sidenav" >
     <%# render "projects/sidebarnav", :as => :project %>
    </div>
      <div id="content">
        <%= yield %>
      <%= render "calculators/vdrop" unless @disable_vdrop %>
      <%# render "sections/pdf" unless @disable_pdf %>
      <%# render "sections/text" unless @disable_text %> 

      </div>
    </div>
    <%= render "layouts/footer" %>
  </body>
</html>

以下是获得的索引表:

<% @page_title = "Sections" %>

<%= link_to("<< Back to Sheets", {:controller => 'sheets', :action => 'index', :project_id => @sheet.project_id}, :class => 'back-link') %>

<div class="sections index">
  <h2>Sections</h2>

  <%= link_to("Add New Section", {:action => 'new', :sheet_id => @sheet.id, :sheet_id => @sheet.id}, :class => 'action new') %>

  <table class="listing" summary="Section list">
    <tr class="header">
      <th>&nbsp;</th>
      <th>Sheet</th>
      <th>Section</th>
      <th>Content Type</th>
      <th>Visible</th>
      <th>Actions</th>
    </tr>
    <% @sections.each do |section| %>
    <tr>
      <td><%= section.position %></td>
      <td><%= section.sheet.title if section.sheet %></td>
      <td><%= section.name %></td>
      <td><%= section.content_type %></td>
      <td class="center"><%= status_tag(section.visible) %></td>
      <td class="actions">
        <%= link_to("Show", {:action => 'show', :id => section.id, :sheet_id => @sheet.id}, :class => 'action show') %>
        <%= link_to("Edit", {:action => 'edit', :id => section.id, :sheet_id => @sheet.id}, :class => 'action edit') %>
        <%= link_to("Delete", {:action => 'destroy', :id => section.id, :sheet_id => @sheet.id}, :class => 'action delete', :confirm => 'Are you sure? This sheet cannot be recovered once deleted') %>
      </td>
    </tr>


    <% end %>
  </table>
</div>

0 个答案:

没有答案