Home how to call action from model to controller in ruby on rails

how to call action from model to controller in ruby on rails

user7388
1#
user7388 Published in September 20, 2018, 12:48 pm

I am trying to call 'checking' action from post model.

class Post < ApplicationRecord
after_commit :testing
def testing
@id = "#{self.id}"
puts @id
checking # call action to controller
end
end


posts_controller.rb

def checking
puts "not Working"
end


I am trying to achieve the above, whereas it is not getting called.

• you should be calling model functions from controller, models should not be aware of controller logics – Subash Feb 13 at 10:22
• What is the reason your doing that? Explain more what are really what to do, because it seems that you are just lost. – araratan Feb 13 at 10:27
• The models should not know about the controller logic. Maybe you can refactor and set some variables from controller to model like it is described in this thread – mmsilviu Feb 13 at 12:07
• What exactly you want? Why you exactly need to call a controller? – Manishh Feb 13 at 12:20