On Jul 6, 3:10 pm, Ralph Shnelvar <[email protected]> wrote:
> If one places a before_filter in class ApplicationController, when is
> the before filter called and for which methods.
>
> I believe it gets called before any "action" ... but how does rails know
> that the method is an action?
> --
> Posted viahttp://www.ruby-forum.com/.

Hi Ralph,

Good question.  Methods in controllers are considered actions only if
they're connected to a url.  Urls are connected to controller methods
by using routes.  The routes.rb file lists all of the routes that will
connect urls to controllers and actions.

In your routes, when you use map.connect (in Rails 1.x, 2.x) you
directly connect a url to an action method.  In Rails 3.0, this is
done with match() instead of connect, but the idea is the same.

If you use map.resources then you're connecting a whole slew of urls
to a certain actions in your controller.  Check the docs for details,
but this is the "restful" style of URL handling, and means that these
methods in your controller will become actions:

index
new
create
edit
update
show
destroy

Finally, be warned that in Rails 1.x and 2.x, when you generate a new
Rails app, by default a pattern-match connector is written for you,
exposing ALL of your methods as actions, which is probably not what
you want.  You should remove or comment those out.

Jeff

purpleworkshops.com

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to