I am using the Devise gem and have the 2 controllers:
1: controllers/admin/mailings_controller.rb:
class Admin::MailingsController < ApplicationController
def self.send_emails
...
RegistrationsController.create
...
end
end
2: controllers/registrations_controller.rb:
class RegistrationsController < Devise::RegistrationsController
...
# POST
def create
# do some stuff
super
# do some stuff
end
...
end
But when I execute (in the console)...
Admin::MailingsController.send_emails
...I get...
"NoMethodError: undefined method `create' for RegistrationsController:Class"
Why? And how to fix this?
rake routes
...shows no problem:
user_registration POST -> /users(.:format) -> registrations#create
Change RegistrationsController.create to RegistrationsController.new.create
OR
change def create to def self.create.
The confusion you have here is using a class method where you mean to call an instance method. You can remedy this by either calling the method on an instance or changing the method to a class method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With