Forum: Ruby on Rails How to use Controller instance methods inside (Web Service) API Services

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Piyush with Rails (Guest)
on 2009-03-04 12:15
(Received via mailing list)
Hi All,

I am using AWS to implement web service APIs in rails and i am using
Layered dispatching mode for implementation.

Here i am not getting how can i use controller's instance methods
(both user defined and built in) inside my API service.

As an example below take below things in consideration.

this is API signature.

class ProductApi < ActionWebService::API::Base

     api_method :find_all_products,
     :returns => [[:int]]

    api_method :find_product_by_id,
    :expects => [:int],
     :returns => [Product]
end

this is layered_backend controller.

class LayeredBackendController < ApplicationController

      dispatching_web_service_mode :layered
      web_service_scaffold :invoke
      web_service(:order) { OrderService.new }

      def test_method
         # some code
      end
end

this is order_service.rb file.

class OrderService< ActionWebService::Base
     web_service_api ProductApi

     def find_all_products
         Product.find(:all).map{ |product| product.id }
     end

     def find_product_by_id(id)
         Product.find(id)
     end
end


Now if i want to use my controller instance method named test_method
inside OrderServie then how can i use it ?

and also how to use controller built in instance methods (like
session, log_error etc )inside OrderService ?


Thanks in Advance.

Piyush.
This topic is locked and can not be replied to.