【问题标题】:How to initialize variable only if it is set up in controller?只有在控制器中设置变量时如何初始化变量?
【发布时间】:2013-06-12 10:16:15
【问题描述】:

只有在控制器中设置的变量才初始化???

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 forms


    【解决方案1】:

    在定义方法时为profile添加默认值,检查是否不是默认值。

    def initialize(profile = nil)
      if profile
        @profile = profile
        @person = profile.person
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2016-03-07
      • 1970-01-01
      • 2020-11-12
      • 2010-10-18
      • 2019-05-17
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多