【问题标题】:Is it possible to move Ruby code from the controller in to a '.js.rjs' file?是否可以将 Ruby 代码从控制器移动到“.js.rjs”文件中?
【发布时间】:2011-01-20 08:38:41
【问题描述】:

我正在使用 Ruby on Rails 3,为了正确组织我的代码,我希望将与动作相关的整个 AJAX 代码分别放在“action.js.rjs”文件中。

例如,如果我在控制器中有这样的代码:

def action
  ...

  format.js {
    # BEGIN code to move in to the 'action.js.rjs' file
    responds_to_parent do
      ...
    end
    # END code to move in to the 'action.js.rjs' file
  }

end

是否可以以某种方式将“responds_to_parent”语句或其内容从控制器移入“action.js.rjs”文件并使其工作?

【问题讨论】:

    标签: ruby-on-rails ruby ajax ruby-on-rails-3 move


    【解决方案1】:

    已解决

    这应该可行:

        responds_to_parent do
          render :action => 'update.js.rjs'
        end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      • 1970-01-01
      • 1970-01-01
      • 2013-11-10
      • 2013-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多