passing parameters to private methods with before_filter

151 views
Skip to first unread message

gete

unread,
Nov 15, 2007, 1:55:03 PM11/15/07
to Ruby on Rails: Talk
Hello,

I was wondering if anybody can show me how to pass parameters to a
Private method with before_filter.
I've tried doing the proc blocked way with

before_filter {|c| c.private_method(params)} ...but this throws an
exception when the method is private.

The rails api says that using the standard symbol reference
( before_filter :private_method) is for private and protected methods
which leads me to assume that using the block method only works for
public methods. Does anybody know how I might pass parameters to a
private method with before_filter?

Thanks
Greg T.

Bob Showalter

unread,
Nov 15, 2007, 2:02:31 PM11/15/07
to rubyonra...@googlegroups.com
On Nov 15, 2007 1:55 PM, gete <greg....@gmail.com> wrote:
>
> Hello,
>
> I was wondering if anybody can show me how to pass parameters to a
> Private method with before_filter.
> I've tried doing the proc blocked way with
>
> before_filter {|c| c.private_method(params)} ...but this throws an
> exception when the method is private.

You can use send:

c.send(:private_method, params)

gete

unread,
Nov 15, 2007, 3:13:12 PM11/15/07
to Ruby on Rails: Talk
Hi Bob,

That worked....thanks so much.

Greg

On Nov 15, 2:02 pm, "Bob Showalter" <showa...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages