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
精彩评论