title: How can access session variable from controller to model in Ruby on Rails
body: <p>I used session variable were <strong>session[:parent]</strong> on controller and I want to these variable pass to model. How do pass a params from controller to model? </p>
  
  <p>Here my controller.rb file</p>
  
  <pre><code>def new
    @child = Child.new
    @child.pickup_people.build
    @classes =  [['Infant', 0], ['Toddlers', 1], ['Early learners', 2], ['Pre school', 3], ['Pre kindergarten', 4]]
    @parent_types =  [['Father', 'father'], ['Mother', 'mother'], ['Other', 'other']]
    @martial_status = [['Married', 'married'], ['Single', 'single'], ['Divorced', 'divorced'], ['Separated', 'separated'], ['Widowed', 'widowed'], ['Other', 'other']]
    @parent = Parent.new
  
   #parents those will be mapped with child, here mentioned to show in form page after creation
  
   if session[:parent_id] != nil
     @parent_sessions = Parent.where(:id =&gt; session[:parent_id])
   end
  end
  
  def create
    logger.debug "\033[31mI am here\033[31m"
    @child = Child.new(child_params)
    if current_user.has_role? :day_care
      @child.day_care_id = current_user.day_care.id
    elsif current_user.has_role? :director
      @child.day_care_id = current_user.director.day_care.id
    elsif current_user.has_role? :assistant_director
      @child.day_care_id = current_user.assistant_director.day_care.id
    elsif current_user.has_role? :teacher
      @child.day_care_id = current_user.teacher.day_care.id
    end
    respond_to do |format|
      if @child.save
      #        logger.debug "\033[31m#{session[:parent_id]}\033[31m"
        if session[:parent] != nil
          session[:parent].each do |p|
            Relative.create(:child_id =&gt; @child.id, :parent_id =&gt; p["id"].to_i, :parent_type =&gt; p["type"])
          end
        end
      ####
        gflash :success =&gt; "Child was succesfully created."
        format.html { redirect_to @child }
        format.json { render :show, status: :created, location: @child }
        session[:parent] = nil
        session[:parent_id] = nil
  
        logger.debug "\033[31mdestroyed#{session[:parent_id]}\033[31m"
      else
        gflash :error =&gt; "Unable to create, please try again."
        format.html { render :new }
        format.json { render json: @child.errors, status: :unprocessable_entity }
      end
    end
  end
  </code></pre>
  
  <p>Thanks for your help!</p>