Filters

Hello,
I'm new to rails and ruby. I'm reading Simply Rails 2, and working
through the chapters to learn how to use rails.

-- backstory --
We're on chapter 8 or so where we are learning about filters.

At this step we are to add a before_filter, like so:

before_filter :login_required, :only => [:new, :create]

I've looked around for details, but the rails docs offer this:

before_filter(*filters, &block)
  Alias for append_before_filter

and:

append_before_filter(*filters, &block)
  The passed filters will be appended to the filter_chain and will
execute before the action on this controller is performed.
  This method is also aliased as before_filter

-- actual question --

What I want to know is: Given this documentation, how would a user
know that there is an :only, and an :except parameter, and what they
take?

Is it some ruby feature of &block paramters that I can toss in a hash?
How do I find out what the valid keys are for such hash, and what they
do?

Thanks,
John Schank

before_filter(*filters, &block)
Alias for append_before_filter

and:

append_before_filter(*filters, &block)
The passed filters will be appended to the filter_chain and will
execute before the action on this controller is performed.
This method is also aliased as before_filter

-- actual question --

What I want to know is: Given this documentation, how would a user
know that there is an :only, and an :except parameter, and what they
take?

You probably wouldn't. :only and :except should be arrays of actions that filter should apply or not apply to.
Some thing has gone funny with the docs on api.rubyonrails.org, as there's a whole swathe of info about filters that has gone. You can still read it here.

Is it some ruby feature of &block paramters that I can toss in a hash?
How do I find out what the valid keys are for such hash, and what they
do?

No, the &block stuff gives the method any block specified as a proc object.

the magic hash parameter is swallowed up by the parameter with a splat

Fred

Ah. Ok.
Thanks for the reply.

I come from Java development, and I've been using Netbeans as my rails
IDE (though I know you don't actually need one) And one thing I really
miss is the abilty to highlight a method and get pop up help about it.
Or to have intellisense which shows the possible alternatives.

Following a tutorial book is all well and good, but it only shows you
how to do specifically what the tutorial shows. I'm finding it a
little bit difficult to see alternatives and possibilities in the
Rails / Ruby docs.

I suppose I'll be browsing here a lot more.
:slight_smile:

Ah. Ok.
Thanks for the reply.

I come from Java development, and I've been using Netbeans as my rails
IDE (though I know you don't actually need one) And one thing I really
miss is the abilty to highlight a method and get pop up help about it.
Or to have intellisense which shows the possible alternatives.

The problem in this particular case is that the documentation got
mashed. I don't know netbeans, but i'd be surprised if it didn't have
some sort of documentation lookup. I use textmate as my editor and if
I hit control H I get the rdoc for the method in question

Fred