Arw50452
Arw50452

Reputation: 325

Rails Call 'Create' Action from Another Controller

In Rails, I'm attempting to create a notification system where notifications will be created automatically when certain controller actions are called. I have the following 'create' action in the notifications controller:

def create
    @notification = Notification.new(notification_params)
    @notification.save

end

I need to call this action from other controller actions, and pass different parameter values to it depending on which controller action calls it. After creating the new notification, I need to continue running code in the controller action that calls it.

Is this possible?

Upvotes: 0

Views: 1500

Answers (1)

Stanislav Mekhonoshin
Stanislav Mekhonoshin

Reputation: 4386

Move this method to application_controller.rb and allow to pass params to it.

Then you'll be able to call it from any controller method

Upvotes: 1

Related Questions