नियंत्रक नाम का उपयोग करने के बजाय, मैं इस तथ्य का लाभ उठाने की सलाह दूंगा कि नियंत्रक अपने माता-पिता से अपने फ़िल्टर प्राप्त करते हैं।
# app/controllers/application_controller.rb
class ApplicationController
# no filters here
end
# app/controllers/authenticated_controller.rb
class AuthenticatedController < ApplicationController
before_filter :login_required
end
# app/controllers/some_other_controller.rb
class SomeOtherController < AuthenticatedController
# inherits the before_filter from AuthenticatedController
# use this for most of your other controllers
end
# app/controllers/unauthenticated_controller.rb
class UnauthenticatedController < ApplicationController
# no filters, since this inherits directly from ApplicationController
# use this for the controller that you don't want to check login on
end
इसका मतलब यह है नियंत्रकों पता है कि क्या वे लॉगिन जाँच करने के लिए, बल्कि एक (संभवतः भंगुर) नामों की सूची की तुलना में माना जाता कर रहे हैं: तो क्या मैं सलाह देते हैं कुछ इस तरह है।
स्रोत
2014-06-18 19:39:42