Calling a controller method from another controller

I have a rest endpoing that allows my users to create a new subscriber
by posting to the subscribers collection, e.g.:

[POST] sevice/subscribers

Although, this is fine for outsiders using the API, I need have an
internal app that needs to call the API too. Actually, it’s in the
same project at /subscription. It’s just a signup form which posts to
the subscribers collection. And since it’s in the same project I would
like to “over ride” the create method of my subscribers_controller.

For example, a method called create_subscriber in
subscription_controller (my signup form). In create_subscriber I would
like to post to the subscribers collection like previously, but I
would also like to do some additional processing after it comes back
successful.

class SubscriptionController < ApplicationController

def index

render page…

end

def create_subscriber
#post to subscribers collection with @subscriber =
Subscriber.new(params[:subscriber])

do additional processing

end

end

Here’s the problem. There’s duplication there, the subscriptions
controller has the same exact code to create a new subscriber. How can
I just call the SubscriptionsController.create to remove this
duplication?

eggie5 wrote:

render page…

Here’s the problem. There’s duplication there, the subscriptions
controller has the same exact code to create a new subscriber. How can
I just call the SubscriptionsController.create to remove this
duplication?

You can move that method into application.rb which is the parent class
of your controllers.


Michael W.