Ruby on rails 控制器中的不同渲染布局未在rails中正确加载
在我的控制器中,我有2个布局,但重定向后布局何时不改变?我不会仅仅采取行动:使用布局“应用程序”新建行项目,另一个使用布局“前布局” 我的控制器:Ruby on rails 控制器中的不同渲染布局未在rails中正确加载,ruby-on-rails,layout,controller,Ruby On Rails,Layout,Controller,在我的控制器中,我有2个布局,但重定向后布局何时不改变?我不会仅仅采取行动:使用布局“应用程序”新建行项目,另一个使用布局“前布局” 我的控制器: class HomeController < ApplicationController layout :compute_layout before_filter :collect_menu, :only => [:show_item, :location, :order_items, :new_line_items
class HomeController < ApplicationController
layout :compute_layout
before_filter :collect_menu, :only => [:show_item, :location, :order_items, :new_line_items]
def index
@stores = Store.all
if !params[:store_id].blank?
@store = Store.find(params[:store_id])
menu_left_all(params[:store_id]) if !@store.blank?
end
end
def show_item
@store = Store.find(params[:store_id])
item_childs(params[:id])
end
def location
@store = Store.find(params[:store_id])
end
def new_line_items
end
def create_line_items
@store = Store.find(params[:store_id])
item = Item.find(params[:id])
line_items = item.line_items.build(quantity: params[:quantity])
respond_to do |format|
if line_items.save
format.html { redirect_to stores_url, notice: 'Line Items was successfully created.' }
end
end
end
def compute_layout
if request.url.include?("new_line_items")
action_name = "application"
else
action_name = "front_layout"
end
end
end
class HomeController[:显示\u项,:位置,:订单\u项,:新建\u行\u项]
def索引
@stores=Store.all
如果参数[:store_id]。是否为空?
@store=store.find(参数[:store\u id])
菜单\左\全部(参数[:存储\ id])如果@商店。空白?
终止
终止
def显示项目
@store=store.find(参数[:store\u id])
项目(参数[:id])
终止
def位置
@store=store.find(参数[:store\u id])
终止
def新产品线项目
终止
def创建行项目
@store=store.find(参数[:store\u id])
item=item.find(参数[:id])
行项目=项目。行项目。生成(数量:参数[:数量])
回应待办事项|格式|
如果行_items.save
format.html{重定向至存储区url,注意:'行项目已成功创建。}
终止
终止
终止
def计算单元布局
if request.url.include?(“新行项目”)
操作\u name=“应用程序”
其他的
操作\u name=“前\u布局”
终止
终止
终止
摆脱您的计算布局方法,将布局:计算布局'更改为布局“前布局”。这将为所有操作设置默认布局
要更改单个操作的布局,请执行以下操作:
def new_line_items
render layout: 'application'
end
另一个解决方案:
如果您认为布局将来可能会更改,则应保留您的compute\u layout
方法,但要更改它:
def compute_layout
if action_name == "new_line_items"
"application"
else
"front_layout"
end
end