小编gui*_*ato的帖子

Rails在before_filter方法中设置布局

是否可以在Rails 3中的before_filter方法中重置默认布局?

我有以下作为我的contacts_controller.rb:

class ContactsController < ApplicationController
  before_filter :admin_required, :only => [:index, :show]
  def show
    @contact = Contact.find(params[:id])
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @contact }
    end
  end
  [...]
end
Run Code Online (Sandbox Code Playgroud)

以及我的application_controller.rb中的以下内容

class ApplicationController < ActionController::Base
  layout 'usual_layout'
  private
  def admin_required
    if !authorized?          # please, ignore it. this is not important
      redirect_to[...]
      return false
    else
      layout 'admin'  [???]  # this is where I would like to define a new layout
      return true …
Run Code Online (Sandbox Code Playgroud)

layout ruby-on-rails before-filter

20
推荐指数
2
解决办法
1万
查看次数

标签 统计

before-filter ×1

layout ×1

ruby-on-rails ×1