Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 仅在写入渲染时进行布局渲染:布局=>';应用程序';利用一切资源_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 仅在写入渲染时进行布局渲染:布局=>';应用程序';利用一切资源

Ruby on rails 3 仅在写入渲染时进行布局渲染:布局=>';应用程序';利用一切资源,ruby-on-rails-3,Ruby On Rails 3,代码:, 我试图在控制器中使用继承,但出于某种原因,布局是这样工作的,我想我做错了什么,但我看不出来 class StandardController < ApplicationController attr_accessor :model, :url handles_sortable_columns def index @records = @model.all @q = model.search params[:q] @records = @q.r

代码:, 我试图在控制器中使用继承,但出于某种原因,布局是这样工作的,我想我做错了什么,但我看不出来

class StandardController < ApplicationController
  attr_accessor :model, :url
  handles_sortable_columns

  def index
    @records = @model.all
    @q = model.search params[:q]
    @records = @q.result(:distinct => true).order(sortable_column_order).paginate(:page => params[:page], :per_page=>10)

    #I'm not sure why I have to do this on every method
    #but if I don't rails doesn't recognize layout
    render :layout => 'application'
  end

  def new
    @record = @model.new
    render :layout => 'application'
  end

  def edit
    @record = @model.find(params[:id])
    render :layout => 'application'
  end

  def show
    @record = @model.find(params[:id])
    render :layout => 'application'
  end

  def create
    @record = @model.new(params[@model.to_s.downcase])

    respond_to do |format|
      if @record.save
        format.html { redirect_to @url, notice: 'Successfully created.' }
      else
        format.html { render action: "new" }
      end
    end
  end

  def update
    @record = @model.find(params[:id])

    respond_to do |format|
      if @record.update_attributes(params[@model.to_s.downcase])
        format.html { redirect_to @url, notice: 'Successfully updated.' }
      else
        format.html { render action: "edit" }
      end
    end
  end

  def destroy
    @record = @model.find(params[:id])
    @record.destroy

    respond_to do |format|
      format.html { redirect_to @url }
    end
  end
end


class DepartmentsController < StandardController 

  before_filter do
    @url = departments_url
    @edit_record_path = lambda {|record| edit_department_path(record) }
    @new_record_path = new_department_path
    @title = "Departments" 
  end

  def initialize
    @model = Department
  end
end

您可以在应用程序控制器中指定布局

只要加上这一行。应用程序必须位于layout/application.html.erb中

layout 'application'

它不起作用,我不知道为什么,我试着在每个控制器中写这行,但也不起作用。
layout 'application'