Daniel Buchan
2011-Nov-07 11:04 UTC
access requesting IP from actionwebservice controller/model
I''m building a SOAP server for a rails project we have here. I''m using actionwebservice to achieve this. Inside the logic for one of the SOAP methods I need to read the IP address of the requesting client. For a regular rails controller we''ve been using this construct, which works nicely -------------------------------------------- tmp_ip = request.env["HTTP_X_FORWARDED_FOR"] if(tmp_ip =~ /(\d+\.\d+\.\d+\.\d+)$/) tmp_ip = $1; else tmp_ip = request.remote_ip end -------------------------------------------- But if I put that in either my webservice method or my webservice controller I just get this error: "undefined local variable or method `request'' for PsipredApiController:Class" Here''s the controller: -------------------------------------- class PsipredApiController < ApplicationController web_service_dispatching_mode :delegated @tmp_ip = request.env["HTTP_X_FORWARDED_FOR"] if(@tmp_ip =~ /(\d+\.\d+\.\d+\.\d+)$/) @tmp_ip = $1; else @tmp_ip = request.remote_ip end web_service :api_disopred, ApiDisopredService.new web_service_scaffold :invoke end -------------------------------------- Here''s the API defs ------------------------------------- class ApiDisopred < ActionWebService::API::Base api_method :submit, :expects => [{:sequence=>:string}, {:email=>:string},{:name=>:string}, {:fpr => :string}, {:psiblast => :string}, {:psipred => :string}], :returns => [SubmitMessage] api_method :results, :expects => [{:job_id=>:string}], :returns => [:string] end ------------------------------------- and here''s the methods ------------------------------------- class ApiDisopredService < ActionWebService::Base web_service_api ApiDisopred def submit(sequence, email, name, fpr, psiblast, psipred) [A GREAT DEAL OF LOGIC THAT WORKS] results = SubmitMessage.new results.message = @message results.job_id = @job.id results.state = @state return results end end --------------------------------------- I hope someone can suggest a fix. Thanks, Daniel -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.