In my application i need to set some deafult actions for all format.js and format.htm responses. At this moment I have something like this in all controllers:
def index
  @users = User.all
  respond_to do |format|
    for开发者_如何学Cmat.html {html_response}
    format.js {js_response}
  end
end
But I think that it isn't a good solution. What can I do?
Make a private method in your ApplicationController and call it from wherever required
class ApplicationController < ActionController::Base
  …
  private
  def default_responses
    respond_to do |format|
      format.html {html_response}
      format.js   {js_response}
    end
  end
end
class SomethingsController < ApplicationController
  def index
    @somethings = Something.all
    default_responses
  end
end
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论