Service objects pattern in Ruby on Rails -
i´m trying develop service class provides payment services in rails app, it´s not working.
service class (lib/paypal_service.rb) (not sure if should placed here, read in posts):
class paypalservice attr_reader :api #, :express_checkout_response def initialize() @api = paypal::sdk::merchant::api.new end def test() puts "congratulations, have called test" end end controller (uses service):
class bookingscontroller < applicationcontroller include boatshelper require 'paypal_service' def create paypalservice.test end ... in output get:
nomethoderror (private method `test' called paypalservice:class):
use paypalservice.new.test instead of paypalservice.test test instance method of class paypalservice , not class method. update below:
class bookingscontroller < applicationcontroller include boatshelper require 'paypal_service' def create paypalservice.new.test end ... note:
if want call paypalservice.test can convert test class method follows:
class paypalservice attr_reader :api #, :express_checkout_response def initialize @api = paypal::sdk::merchant::api.new end def self.test puts "congratulations, have called test" end end
Comments
Post a Comment