简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM