AWDWR- Question

I’m having a particularly difficult time undersanding one lesson from
this book. This is in relation ot how one would grab “search”
parameters from web forms to search for records in the database. I
understand the :conditions part of find() but am confused on the code:

1- name = params[:name]
pos = Order.find(:all,
:conditions => [“name = ? and pay_type = ‘po’” , name])

2- name = params[:name]
pay_type = params[:pay_type]
pos = Order.find(:all,
:conditions => [“name = :name and pay_type = :pay_type” ,
{:pay_type => pay_type, :name => name}])

3- pos = Order.find(:all,
:conditions => [“name = :name and pay_type = :pay_type” , params])

Also, I know what a hash is but don’t understand how it’s being used in
2 & 3.

TIA
Stuart

Was this question not explained well ?

It’s 3 ways (according to AWDWR that you can grab back search
parameters from forms, but in the first one, I understand the ? but
then it says the 2nd element replaces the first question mark ?, that
is confusing me.

Stuart

On 6/19/06, Dark A. [email protected] wrote:

Was this question not explained well ?

Try coding you up a page that contains the line:

<%= debug(:params) %>

And see if it makes more sense. Also skip forward to the Appendix and
check out Hashes (pg 562-564 by “corner” page numbers). It’s
basically a substitution system, anything in the hash gets substituted
for an appropriate symbol in the string.

In fact reading the whole Appendix on Ruby will probably help with the
syntactic issues. :slight_smile:

-Curtis

I was king of thinking along the substitution angle. I’ll check the
material you reference.
On a related note,
I’m in script / console
and I can’t initiate a variable with params
i type name = params[:name]
and the error comes back as undefine method or variable.

Stuart

You didn’t ask a question – you said you were confused.

http://api.rubyonrails.org/

Look under ActiveRecord::Base and read all about, which based on your
question you clearly haven’t done.

Ouch! I havent dug into the api docs yet as I’m still winding my way
through the book.

Stuart

On 6/19/06, Curtis [email protected] wrote:

Try coding you up a page that contains the line:

<%= debug(:params) %>

I got back
— :params.

Stuart

On 6/19/06, Dark A. [email protected] wrote:

i type name = params[:name]
and the error comes back as undefine method or variable.

http://api.rubyonrails.org/

ActionController::Base

[RW] params Holds a hash of all the GET, POST, and Url parameters
passed to the action. Accessed like params[“post_id”] to get the
post_id. No type casts are made, so all values are returned as
strings.

Only available in the context of a superclass of
ActionController::Base. :slight_smile: (I.E. An incoming request being
processed by a Controller). Thusly if you add my original line of
code into an .rhtml template (that was called as a result of a web
form submission) you should see the params array.

-Curtis

-Curtis

On Mon, 2006-06-19 at 13:39 -0600, Dark A. wrote:

On 6/19/06, Curtis [email protected] wrote:

Try coding you up a page that contains the line:

<%= debug(:params) %>


<%= debug params %>

Craig

On 6/19/06, Curtis [email protected] wrote:


<%= debug params %>

Doh! Crap…sorry…heehee… Working with Java at the moment and
had my syntax munged. :wink:

No problem, I haven’t created a form yet and at this point will
probably hold off. There has got to be some documentation about
params around somehere. Hashes and arrays I understand, it’s the
syntax of the conditions string that I’m having an extremely hard time
figuring out. Up to now, most of Ruby and Rails makes sense to me.

Stuart

On Mon, 2006-06-19 at 14:52 -0600, Dark A. wrote:

probably hold off. There has got to be some documentation about
params around somehere. Hashes and arrays I understand, it’s the
syntax of the conditions string that I’m having an extremely hard time
figuring out. Up to now, most of Ruby and Rails makes sense to me.


params is the hash that results from the post action.

Craig

On 6/19/06, Craig W. [email protected] wrote:

On Mon, 2006-06-19 at 13:39 -0600, Dark A. wrote:

On 6/19/06, Curtis [email protected] wrote:

Try coding you up a page that contains the line:

<%= debug(:params) %>


<%= debug params %>

Doh! Crap…sorry…heehee… Working with Java at the moment and
had my syntax munged. :wink:

It’s clearer to me now. Thanks for the help.
Stuart

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs