Varun Goel
2008-Apr-24 11:48 UTC
How to add parameter and condition in function dynamically??
Hi All,
I have one function in that function i wanna add parameters and
conditions dynamically.
I hope you got me if yes please tell me what should i do.
Thanks
Varun Kumar
--
Posted via http://www.ruby-forum.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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Apr-24 11:55 UTC
Re: How to add parameter and condition in function dynamically??
On 24 Apr 2008, at 12:48, Varun Goel wrote:> > Hi All, > I have one function in that function i wanna add parameters and > conditions dynamically. > > I hope you got me if yes please tell me what should i do. >You''re going to have to be more specific. Fred>--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Danimal
2008-Apr-24 14:24 UTC
Re: How to add parameter and condition in function dynamically??
If you have: def foo(*bar) bar.class # => Array end So the parameters becomes an array of values, including an empty array if nothing is passed in. Then you can do stuff like: foo foo "one", "two" foo :a => "b" etc. Is that what you were looking for? -Danimal On Apr 24, 5:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 24 Apr 2008, at 12:48, Varun Goel wrote: > > > > > Hi All, > > I have one function in that function i wanna add parameters and > > conditions dynamically. > > > I hope you got me if yes please tell me what should i do. > > You''re going to have to be more specific. > > Fred > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV
2008-Apr-24 16:33 UTC
Re: How to add parameter and condition in function dynamically??
Another pseudo-random guess...
I''ve had several places where I''ve done something like this in
a
controller:
FIND_OPTIONS = {:limit=>10, :offset=>0, :order=>:name}
def index
find_options = FIND_OPTIONS.dup
find_options.reverse_merge :name=>params[:name] if
params[:name].blank?
... other options...
SomeModel.find(:all, find_options)
end
That allows you to search only for arguments that are supplied by the
user (ignoring blanks as don''t cares).
If you want to only add/update data as returned from a form
submission... Rails already does that for you.
On Apr 24, 10:24 am, Danimal
<fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> If you have:
>
> def foo(*bar)
> bar.class # => Array
> end
>
> So the parameters becomes an array of values, including an empty array
> if nothing is passed in.
>
> Then you can do stuff like:
>
> foo
> foo "one", "two"
> foo :a => "b"
> etc.
>
> Is that what you were looking for?
>
> -Danimal
>
> On Apr 24, 5:55 am, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
>
> > On 24 Apr 2008, at 12:48, Varun Goel wrote:
>
> > > Hi All,
> > > I have one function in that function i wanna add parameters
and
> > > conditions dynamically.
>
> > > I hope you got me if yes please tell me what should i do.
>
> > You''re going to have to be more specific.
>
> > Fred
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---