小编Ant*_*ect的帖子

关闭其中一个操作的布局

我的情况: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)

我该怎么办?

layout ruby-on-rails

78
推荐指数
3
解决办法
6万
查看次数

如何在控制器方法之间传递值

有没有办法在控制器方法之间共享一个数组并存储它直到页面重新加载或调用另一个控制器的方法?有些方法应该更改数组.

ruby-on-rails

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

源反射宏无效:has_many:through

我有这样愤怒的联想:融资> - 事件> - 子程序> - 程序.我希望通过所有程序从程序访问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)

ruby activerecord ruby-on-rails has-many-through

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