Hi all, We are in a ''web-service-like'' scenario in which a controller action needs to save some things to the database and issue a couple of POSTS/GETS to other servers. These aren''t web services, per se, but rather perl scripts on a wiki. My solution feels clunky, and I wondered if there''s a cleaner way. class AccountController require ''net/http'' require ''uri'' def create # Create account in DB ... account.save! # Create account page on wiki wiki_url = URI.parse(''http://ourwiki/save_page'') result = Net::HTTP.post_form(wiki_url, {:page_name => account.name + ''Page''}) raise "Couldn''t create" unless response.body =~ /Welcome to #{account.name}/ redirect_to :action => ''show'', :id => account.id end end Thanks. Brian -- 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 -~----------~----~----~----~------~----~------~--~---
Brian Hartin wrote:> Hi all, > > We are in a ''web-service-like'' scenario in which a controller action > needs to save some things to the database and issue a couple of > POSTS/GETS to other servers. These aren''t web services, per se, but > rather perl scripts on a wiki. My solution feels clunky, and I wondered > if there''s a cleaner way. > > class AccountController > require ''net/http'' > require ''uri'' > > def create > # Create account in DB > ... > account.save! > > # Create account page on wiki > wiki_url = URI.parse(''http://ourwiki/save_page'') > result = Net::HTTP.post_form(wiki_url, {:page_name => account.name + > ''Page''}) > raise "Couldn''t create" unless response.body =~ /Welcome to > #{account.name}/ > > redirect_to :action => ''show'', :id => account.id > end > endFirst, I would move this to the model. after_save :create_wiki_page def create_wiki_page Net::Http.post_form(...) end And if the interface got to be more than this one point of connection, I would move it to an API library module WikiApi def self.create_user_page(user) .. end def self.create_project_page(user, project) ... end end # in the model after_save :create_wiki_page def create_wiki_page WikiApi.create_user_page(self) end def create_project(project_attributes) p = user.projects.create(project_attributes) WikiApi.create_project_page(user, p) end Or something... -- 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 -~----------~----~----~----~------~----~------~--~---
Alex Wayne wrote:> Brian Hartin wrote: >> Hi all, >>[...]> Or something...Makes perfect sense. Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---