Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #431 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

[PATCH] Conditional filters

Reported by: marcel Assigned to: David
Priority: normal Milestone:
Component: ActionPack Version: 0.9.2
Severity: normal Keywords:
Cc:

Description

This patch adds an :only_on and an :except_on condition to before and after filters for your controllers. For example:

class JournalController < ActionController::Base
  # only require authentication if the current action is edit or delete
  before_filter :authorize, :only_on => [ :edit, :delete ]

  private
    def authorize
      # redirect to login unless authenticated
    end
end

The condition hashes accept an arbitrary number of method references, so :except_on => :my_birthday and :except_on => [ :my_birthday, :weekends ] are both valid.

Attachments

AP-conditional_filters.patch (8.1 kB) - added by marcel on 01/06/05 17:45:41.
Adds conditional filters with tests
AS-write_inheritable_hash.patch (0.6 kB) - added by marcel on 01/06/05 17:46:33.
Adds write_inheritable_hash on which conditional filters depend
AP-conditional_filters_all_types.patch (11.6 kB) - added by marcel on 01/08/05 17:56:03.
Replaces AP-conditional_filters.patch, allowing conditions on all filters types
AP-conditional_filters_all_types_doc_fix.patch (11.6 kB) - added by marcel on 01/08/05 18:02:16.
Previous patch had documentation type (sorry)
AP-conditional_filters_all_types_correct_ordering.patch (13.0 kB) - added by marcel on 01/08/05 19:12:07.
This version respects the ordering of passed in filters. Replaces all previous AP-* patches attached.
AP-conditional_filters_cleaned_up.patch (12.9 kB) - added by marcel on 01/09/05 00:12:30.
Some minor improvements

Change History

01/06/05 17:45:41 changed by marcel

  • attachment AP-conditional_filters.patch added.

Adds conditional filters with tests

01/06/05 17:46:33 changed by marcel

  • attachment AS-write_inheritable_hash.patch added.

Adds write_inheritable_hash on which conditional filters depend

01/08/05 17:56:03 changed by marcel

  • attachment AP-conditional_filters_all_types.patch added.

Replaces AP-conditional_filters.patch, allowing conditions on all filters types

01/08/05 17:59:25 changed by marcel

AP-conditional_filters_all_types.patch replaces AP-conditional_filters.patch.

It changes the condition terms from :only_on and :except_on to just :only and :except. It also allows conditions to be set on all three types of filters (method reference, inline method and fitler class).

It still depends on AS-write_inheritable_hash.patch.

01/08/05 18:02:16 changed by marcel

  • attachment AP-conditional_filters_all_types_doc_fix.patch added.

Previous patch had documentation type (sorry)

01/08/05 18:03:08 changed by marcel

AP-contidional_filters_all_types.patch had a typo it its docs (sorry).

The correct patch is AP-conditional_filters_all_types_doc_fix.patch

01/08/05 19:12:07 changed by marcel

  • attachment AP-conditional_filters_all_types_correct_ordering.patch added.

This version respects the ordering of passed in filters. Replaces all previous AP-* patches attached.

01/08/05 19:14:50 changed by marcel

Following a suggestion by bitsweat this new iteration of the patch respects the ordering of Procs passed to the filter macros in the event that a mixture of filter types are used in one call by splitting up the procedure of extracting conditions and creating condition hashes into separate operations.

This replaces AP-conditional_filters_all_types_doc_fix.patch

Still depends on AS-write_inheritable_hash.patch

01/09/05 00:12:30 changed by marcel

  • attachment AP-conditional_filters_cleaned_up.patch added.

Some minor improvements

01/09/05 17:06:47 changed by david

  • status changed from new to closed.
  • resolution set to fixed.