# How to search from Flex 3 (NEWBIE)

**URL:** <https://www.ruby-forum.com/t/how-to-search-from-flex-3-newbie/173789>\
**Category:** Rails\
**Created:** [August 14, 2009, 7:38pm UTC](https://www.ruby-forum.com/t/how-to-search-from-flex-3-newbie/173789 "2009-08-14T19:38:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![c0y0tex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@c0y0tex](https://www.ruby-forum.com/u/c0y0tex)\
**Post date:** [August 14, 2009, 7:38pm UTC](https://www.ruby-forum.com/t/how-to-search-from-flex-3-newbie/173789/1 "2009-08-14T19:38:12Z")

</div>

Hi, first of all let me say that I’m a Flex developer just getting  
into the awesome world of Ruby on Rails, so I consider myself a newbie  
on RoR. what I need to do is to search for a specific row on the table  
and return the complete row in xml format, the thing is that I need to  
search by description rather than by id, so I did this:

class LoginController \< ApplicationController

# GET /login

# GET /login/usuario.xml

def search  
t = params[:usuario]  
@usuario = Usuario.first(:conditions =\> [“usuario = ?”, “t”])

```
respond_to do |format|
  format.xml { render :xml => @usuario }
end

```

end  
end

but I don’t know what U.R.L. to specify on the HTTPService tag on  
flex. I don’t even know how to test if this def search is working from  
a browser, can anyone please help me on this one, I’m desperate, I  
have a deadline to meet and I’m stuck, please please please help, ANY  
HELP will be appreciated.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![c0y0tex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@c0y0tex](https://www.ruby-forum.com/u/c0y0tex)\
**Post date:** [August 14, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/how-to-search-from-flex-3-newbie/173789/2 "2009-08-14T20:00:27Z")

</div>

Hi c0y0tex,

On Fri, 2009-08-14 at 10:37 -0700, c0y0tex wrote:

> ```
> t = params[:usuario]
> @usuario = Usuario.first(:conditions => ["usuario = ?", "t"])
> 
> ```

You’re missing the find method so unless your Usuario class has defined  
a ‘first’ method the code above should be throwing an error. Isn’t it?

Try…  
@usuario = Usuario.find(:first, :conditions =\> [“usuario = ?”, “t”])

> ```
> respond_to do |format|
> format.xml { render :xml => @usuario }
> end
> 
> ```
> 
> end  
> end
> 
> but I don’t know what U.R.L. to specify on the HTTPService tag on  
> flex.

I know nothing about flex, but if you’re just trying to call this  
method the url would be, assuming development mode,

[http://localhost:3000/login/search](http://localhost:3000/login/search)

> I don’t even know how to test if this def search is working from  
> a browser

First thing to do is find out if it’s working at all, then tackle the  
various delivery agents.

Easiest thing to do is throw a ‘puts’ in after the find…

puts “@usuario = #{@usuario.inspect}”

will display the value in your console window.

Entering the url above in your browser will display the xml content.

> , can anyone please help me on this one, I’m desperate, I  
> have a deadline to meet and I’m stuck, please please please help, ANY  
> HELP will be appreciated.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![c0y0tex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@c0y0tex](https://www.ruby-forum.com/u/c0y0tex)\
**Post date:** [August 14, 2009, 8:42pm UTC](https://www.ruby-forum.com/t/how-to-search-from-flex-3-newbie/173789/3 "2009-08-14T20:42:00Z")

</div>

On Aug 14, 1:59 pm, bill walton [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > # GET /login
> > 
> > # GET /login/usuario.xml
> > 
> > def search  
> > t = params[:usuario]  
> > @usuario = Usuario.first(:conditions =\> [“usuario = ?”, “t”])

Are seems like you want

@usuario = Usuario.first(:conditions =\> [“usuario = ?”, t])

instead (though for simple where clauses based on equality, I prefer  
the hash notation. not really important though)

> You’re missing the find method so unless your Usuario class has defined  
> a ‘first’ method the code above should be throwing an error. Isn’t it?

ActiveRecord::Base#first and #all have been convenience methods for  
awhile now

> First thing to do is find out if it’s working at all, then tackle the  
> various delivery agents.
> 
> Easiest thing to do is throw a ‘puts’ in after the find…
> 
> puts “@usuario = #removed\_email\_address@domain.invalid}”
> 
> will display the value in your console window.

Bad idea, this only works if your running your development server  
via ./script/server non-daemonized (i think?) in a terminal window  
thats still open. For hacky quick&dirty variable inspection i like  
doing

raise expression.inspect

though really you’ll just be having calls to Rails.logger.debug all  
over the place (and of course tail’ing the output of development.log).

> > but I don’t know what U.R.L. to specify on the HTTPService tag on  
> > flex. I don’t even know how to test if this def search is working from  
> > a browser, can anyone please help me on this one

well, neither do i. how are your routes set up? definitely worth  
reading [Rails Routing from the Outside In — Ruby on Rails Guides](http://guides.rubyonrails.org/routing.html) to get an  
understanding of this if you don’t have any other resources available  
(although if you haven’t modified your routes.rb (which you _did_ if  
the controller was generated via scaffold) :controller/:action.:format  
is the default…)

---

<div class="post-metadata">

**Author:** ![c0y0tex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@c0y0tex](https://www.ruby-forum.com/u/c0y0tex)\
**Post date:** [August 14, 2009, 8:57pm UTC](https://www.ruby-forum.com/t/how-to-search-from-flex-3-newbie/173789/4 "2009-08-14T20:57:48Z")

</div>

On Fri, 2009-08-14 at 11:41 -0700, pharrington wrote:

> On Aug 14, 1:59 pm, bill walton [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > You’re missing the find method so unless your Usuario class has defined  
> > a ‘first’ method the code above should be throwing an error. Isn’t it?
> 
> ActiveRecord::Base#first and #all have been convenience methods for  
> awhile now

I’d missed that. Thanks.

> via ./script/server non-daemonized (i think?) in a terminal window  
> thats still open. For hacky quick&dirty variable inspection i like  
> doing  
> raise expression.inspect

You ‘like’ doing quick and dirty differently that I. Doesn’t make  
either a ‘bad idea’. I characterized by suggestion as ‘easiest’, and I  
think that measure would hold.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![c0y0tex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@c0y0tex](https://www.ruby-forum.com/u/c0y0tex)\
**Post date:** [August 14, 2009, 10:25pm UTC](https://www.ruby-forum.com/t/how-to-search-from-flex-3-newbie/173789/5 "2009-08-14T22:25:01Z")

</div>

> You ‘like’ doing quick and dirty differently that I. Doesn’t make  
> either a ‘bad idea’. I characterized by suggestion as ‘easiest’, and I  
> think that measure would hold.

Guess I’m just being anal at this point, but I spose even “easy” is  
relative. I run Passenger on my development machine, so apparently  
STDOUT goes to the apache error log, which 1) is hardly an obvious  
place to look for debugging messages once your app actually runs at  
all and 2) I need to become root to view it… hardly convenient.  
raise is nice because no matter how you’re looking at your app (rails  
console, web browser, test suite), the information you’re asking for  
is always smacked right in your face. There’s also no way to forget to  
remove a raise statement put in for debugging purposes… its pretty  
aggressive like that in reminding you of the right way to do things.

---

<div class="post-metadata">

**Author:** ![c0y0tex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@c0y0tex](https://www.ruby-forum.com/u/c0y0tex)\
**Post date:** [August 14, 2009, 11:11pm UTC](https://www.ruby-forum.com/t/how-to-search-from-flex-3-newbie/173789/6 "2009-08-14T23:11:15Z")

</div>

On Fri, 2009-08-14 at 12:57 -0700, pharrington wrote:

> > You ‘like’ doing quick and dirty differently that I. Doesn’t make  
> > either a ‘bad idea’. I characterized by suggestion as ‘easiest’, and I  
> > think that measure would hold.
> 
> Guess I’m just being anal at this point, but I spose even “easy” is  
> relative.

Exactly.

> I run Passenger on my development machine,

If I were running Passenger in development, or as you seemed to  
understand in your earlier post, ‘unless …’ I use mongrel running in  
an open console window without -d, which I do. If I were using  
Passenger, I’m sure I’d prefer your approach. I don’t recall the OP  
stating one way or another. So I should have started my response to  
them with ‘depending on what web server you’re running…’ My bad.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![c0y0tex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@c0y0tex](https://www.ruby-forum.com/u/c0y0tex)\
**Post date:** [August 18, 2009, 6:24pm UTC](https://www.ruby-forum.com/t/how-to-search-from-flex-3-newbie/173789/7 "2009-08-18T18:24:05Z")

</div>

Thanks a LOT for your help guys, the link pharrington provided was  
very very helpful, I managed to do my search, but after I founded  
something called RestfulX which is totally awesome, any Flex developer  
interested in using Ruby on Rails as a data provider web service  
should definitely check it out, it builds the migrations and  
controllers on ruby and the views in Flex, also you can define a  
single file for the scaffolding information (table definitions and  
relations). In top of all it integrates a data handling framework into  
Flex, with this framework you can do filters, deletes, updates and all  
the things you might need for your RIA.

checkit out [http://restfulx.github.com/](http://restfulx.github.com/).

Once again thanks for the help, see you around.

Viktor Amilkar Erickson Reyna López
