# Before\_filter: how to give :except more than 1 value?

**URL:** <https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100>\
**Category:** Rails\
**Created:** [January 11, 2006, 11:12pm UTC](https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100 "2006-01-11T23:12:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [January 11, 2006, 11:12pm UTC](https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100/1 "2006-01-11T23:12:21Z")

</div>

Hi all

I have the following class:

class MemberController \< ApplicationController  
before\_filter :authorize, :except =\> :index

def index  
…  
end

Now I want to give the before\_filter more than one :except argument. I  
tried :except =\> {:index, :login}, but this didn’t work.

How can i accomplish this?

Thanks a lot and have a nice day,  
Josh

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [January 11, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100/2 "2006-01-11T23:17:02Z")

</div>

try array.  
before\_filter :authorize, :except =\>[:index, :except]

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [January 11, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100/3 "2006-01-11T23:18:33Z")

</div>

Maiha wrote:

> try array.  
> before\_filter :authorize, :except =\>[:index, :except]

Thank you. Is %w{ index, login } OK, too?

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [January 11, 2006, 11:19pm UTC](https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100/4 "2006-01-11T23:19:41Z")

</div>

Try putting it in an array rather than a hash, e.g.

before\_filter :authorize, :except =\> [:index, :login]

See under ‘Filter Conditions’:  
[http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html#M000127](http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html#M000127)

csn

— Joshua M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[\[object](https://mail.yahoo.com/)**
>
> \[object

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [January 11, 2006, 11:45pm UTC](https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100/5 "2006-01-11T23:45:05Z")

</div>

Thanks a lot.

But what exactly creates the array now and what the hash?

%w{} should create an array, right?

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [January 11, 2006, 11:53pm UTC](https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100/6 "2006-01-11T23:53:04Z")

</div>

Joshua M. \<forum@…\> writes:

> before\_filter :authorize, :except =\> :index  
> before\_filter :authorize, :except =\> [:index, :login]

-damon

> **[Damon Clinkscales](https://damonc.onuniverse.com/)**
>
> Damon Clinkscales

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [January 15, 2006, 9:56pm UTC](https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100/7 "2006-01-15T21:56:49Z")

</div>

And note that:

%w{index login}

creates this array:

[‘index’, ‘login’]

and this:

[:index, :login]

creates an array of symbols rather than an array of strings.

That should not be a problem, however, because send() accepts strings  
too.

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [January 15, 2006, 9:50pm UTC](https://www.ruby-forum.com/t/before-filter-how-to-give-except-more-than-1-value/61100/8 "2006-01-15T21:50:44Z")

</div>

On Jan 11, 2006, at 4:45 PM, Joshua M. wrote:

> Thanks a lot.
> 
> But what exactly creates the array now and what the hash?

The bare curlies create a hash, braces create an array.

> %w{} should create an array, right?

%w{index login} will also create an array, but be careful not to  
do %w{index, login} with the comma because then the comma becomes  
part of the first array element.

e.g.  
irb(main):001:0\> a1 = [‘index’,‘login’]  
=\> [“index”, “login”]  
irb(main):002:0\> a2 = %w{index login}  
=\> [“index”, “login”]  
irb(main):003:0\> a3 = %w{index, login}  
=\> [“index,”, “login”]

-dudley
