开发者

Is it possible to move Ruby code from the controller in to a '.js.rjs' file?

开发者 https://www.devze.com 2023-02-05 11:19 出处:网络
I am using Ruby on Rails 3 and for a correct organization of my code I would like to have the whole AJAX code related to an action in a respectively \'action.js.rjs\' file.

I am using Ruby on Rails 3 and for a correct organization of my code I would like to have the whole AJAX code related to an action in a respectively 'action.js.rjs' file.

For example, if I have code in a controller like this:

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

is it possible to move in some way the 'responds_to_parent' statement or its content from the controller in to the 'action.js.rjs' file and make it to work?


SOLVED

This should work:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号