How to search from Flex 3 (NEWBIE)

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.

Hi c0y0tex,

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"])

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

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

Hi c0y0tex,

> 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"])

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 = #...@usuario.inspect}"

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 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..)

> 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.

> 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.

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

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

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.

> 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

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/.

Once again thanks for the help, see you around.

Viktor Amilkar Erickson Reyna López