sergiutruta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-07 18:30 UTC
Servlet in RubyOnRails
Hi, I want to develop a controller which acts like a servlet in java. That means it doesn''t have any views associated with it, it just waits for requests and treats those requests. Though it''s not a web service because I don''t want to do RPC from a client, I want to send an XML to it and then this controller will treat the request. How would you implement this? Thanks ;) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 6/7/07, sergiutruta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <sergiutruta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I want to develop a controller which acts like a servlet in java. That > means it doesn''t have any views associated with it, it just waits for > requests and treats those requests. > Though it''s not a web service because I don''t want to do RPC from a > client, I want to send an XML to it and then this controller will > treat the request.At the very least you should at least be returning an HTTP header when the request is processed. If you don''t want a view, thats easy. Just make the actions in your controller look something like this: def request_handler # process the request here... return render(:nothing => true, :status => status_from_processing) end Return a status that is appropriate to the result of whatever processing you have done. If you aren''t familiar with them, you can learn more about them here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html -- F. Morgan Whitney http://www.blizzo.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 -~----------~----~----~----~------~----~------~--~---
sergiutruta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-07 19:03 UTC
Re: Servlet in RubyOnRails
Ok, so I can do this for success: return render(:nothing => true, :status => 200) Thanks for your quick response :) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Ok, so I can do this for success: > > return render(:nothing => true, :status => 200)Rather: render(:nothing=>true, :status=>204) 204 indicates success and no content. - donald --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
There are many options. The controller can render the output directly as either a string or an XML builder. You can directly render RJS output using render :update. You can also use a separate "view" file to render whatever output you like and the controller just provides the raw data. Generally this is the recommended approach. The view does not need to generate HTML for a human. It can render XML for another program. The key idea is to separate the data collection/navigation into the controller and let the formatting/presentation of that be in a separate file called a view. This allows returning the same data in multiple formats using different views. Michael On Jun 7, 11:30 am, "sergiutr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <sergiutr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I want to develop a controller which acts like a servlet in java. That > means it doesn''t have any views associated with it, it just waits for > requests and treats those requests. > Though it''s not a web service because I don''t want to do RPC from a > client, I want to send an XML to it and then this controller will > treat the request. > > How would you implement this? > Thanks ;)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sergiutruta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-07 19:51 UTC
Re: Servlet in RubyOnRails
Michael, I''m not sure I understood it all :) Can you point me to an example please? Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---