ruby - Call 2 post controller methods on single form submission in rails -


i have use case need create 2 tuples ( 1 in invitation , 1 in notification table) on single form submission( action directed invitation#create). how call notification create method invitation create create new tuple in notification table.

ps: no relation between invitation , notification.

you wouldn't go notifications create action, in invitation create. below code use shared concern method, explained below it:

class invitationscontroller < applicationcontroller     include notifications      #....      def create         invitation = invitiation.create(invitation_params)         create_notification(invitation)     end      private      def invitation_params         # strong params code     end end 

so if had second controller/model, e.g rsvp:

class rsvpscontroller < applicationcontroller     include notifications      #....      def create         rsvp = rsvp.create(rsvp_params)         create_notification(rsvp)     end      private      def rsvp_params         # strong params code     end end 

then in controllers/concerns directory, create file 'notifications.rb'

module notifications   extend activesupport::concern    def create_notification(object)     notification.create(object_id: object.id, object_type: object_type)   end end 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -