我的情况:ReportsController的查看操作应该呈现纯HTML,但不能作为文件(在浏览器中查看并保存之后).因此,为了渲染我使用视图模板view.html.erb并且我需要关闭此操作的任何布局.但在此控制器的其他操作中,布局应保持不变.只关闭整个控制器的工作原理如下:
ReportsController < ApplicationController
layout false
Run Code Online (Sandbox Code Playgroud)
但这样做错了:(对于我试图在行动中使用这样的行为的所有动作:
def view
@report = Report.new(params[:report])
unless @report.valid?
render :action => 'new' and return
else
render :layout => false
end
end
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
有没有办法在控制器方法之间共享一个数组并存储它直到页面重新加载或调用另一个控制器的方法?有些方法应该更改数组.
我有这样愤怒的联想:融资> - 事件> - 子程序> - 程序.我希望通过所有程序从程序访问last_financings,因此代码是:
class Fcp < Program
has_many :fcp_subprograms,
:foreign_key => 'parent_id'
has_many :subprogram_last_actual_financings,
:through => :fcp_subprograms,
:source => :last_actual_financings
class FcpSubprogram < Program
belongs_to :fcp,
:class_name => 'Fcp',
:foreign_key => 'parent_id'
has_many :events,
:foreign_key => 'fcp_id'
has_many :last_actual_financings,
:through => :events,
:source => :last_actual_financings
class Event < ActiveRecord::Base
belongs_to :fcp,
:class_name => 'Fcp',
:foreign_key => 'fcp_id'
belongs_to :fcp_subprogram,
:class_name => 'FcpSubprogram',
:foreign_key => 'fcp_id'
has_many :last_actual_financings,
:class_name => 'ActualFinancing',
:order => 'date DESC',
:limit => …Run Code Online (Sandbox Code Playgroud)