Forum: Ruby on Rails before_filter: how to give :except more than 1 value?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2006-01-11 23:12
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
1aa0bfdb1e3a8202e6f0efd30366b516?d=identicon&s=25 Maiha (Guest)
on 2006-01-11 23:17
try array.
  before_filter :authorize, :except =>[:index, :except]
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2006-01-11 23:18
Maiha wrote:
> try array.
>   before_filter :authorize, :except =>[:index, :except]

Thank you. Is %w{ index, login } OK, too?
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 CSN (Guest)
on 2006-01-11 23:19
(Received via mailing list)
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/ActionControlle...

csn

--- Joshua Muheim <forum@josh.ch> wrote:

>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2006-01-11 23:45
Thanks a lot.

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

%w{} should create an array, right?
97a7959f0d9e6c90ddae200520e93067?d=identicon&s=25 Damon Clinkscales (Guest)
on 2006-01-11 23:53
(Received via mailing list)
Joshua Muheim <forum@...> writes:

>   before_filter :authorize, :except => :index
before_filter :authorize, :except => [:index, :login]

-damon
http://damonclinkscales.com/
95eb06f24b2e217e9f290f7227cdbf55?d=identicon&s=25 Dudley Flanders (Guest)
on 2006-01-15 21:50
(Received via mailing list)
On Jan 11, 2006, at 4:45 PM, Joshua Muheim 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
71f1b6b2c3fd9af2e8c52618fb91caa6?d=identicon&s=25 Jules (Guest)
on 2006-01-15 21:56
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.
This topic is locked and can not be replied to.