dimanche 19 juin 2016

Issue related to method arguments in rails

I am facing some problem related to arguments passing in rails. From my controller I want to send a variable as an argument to the request handler job. But I am sure that I am doing something wrong about the variables and arguments. Student is the model name. Actually the students table contains some records. I am facing the following problem.

formal argument can not be an instance variable.

Here is my code:

My app/controllers/students_controller.rb file is:-

class StudentsController < ApplicationController

attr_accessor :xmodel
def new
    @student=Student.new
    @students=Student.all
end

def create
    @student=Student.new(u_params)
    @student.set_insertbool_field

    xmodel=Student.last
    RequestHandlerJob.doit_later(:xmodel)

    if @student.save
        redirect_to new_student_path
    end
end


 def u_params
   params.require(:student).permit(:id , :firstname, :lastname)
 end

end

My app/jobs/request_handler_job.rb file is:

class RequestHandlerJob < ActiveJob::Base
queue_as :default

self.queue_adapter = :sidekiq


def doit_later(:xmodel) 
 # Do something later
 @extract_bool=:xmodel.inserted_bool
  if @extract_bool == 1
    redirect_to new_student_path , :notice => "Inserted and Queued"

  end
 end
end

Aucun commentaire:

Enregistrer un commentaire