我试图registration_insert.rb
从我的控制器中调用我定义的方法,但我不断收到以下错误:
RegistrationInsert:类的未定义方法“插入”
如何正确调用插入方法?
文件结构(全部在 /app 下)
-控制器
---------registrations_controller.rb
-注册
---------registration_insert.rb
注册控制器.rb:
def create
@registration = Registration.new(registration_params)
RegistrationInsert.insert(registration_params)
respond_to do |format|
if @registration.save
format.html { redirect_to @registration, notice: 'Registration was successfully created.' }
format.json { render :show, status: :created, location: @registration }
else
format.html { render :new }
format.json { render json: @registration.errors, status: :unprocessable_entity }
end
end
end
注册插入.rb
module RegistrationInsert
def insert(registration)
#method code
end
end
编辑:将类更改为模块,它给了我这个错误:
RegistrationInsert:Module 的未定义方法“插入”