2011-03-27 3 views
3

dans lib/my_lib.rbméthode non définie output_buffer = » pour content_tag avec le bloc

class MyLib 
    include ActionView::Helpers::TagHelper 

    def foo 
     content_tag :div do 
     "hello" 
     end 
    end 
end 

donne une

require 'lib/my_lib' ;MyLib.new.foo 
NoMethodError: undefined method `output_buffer=' for #<MyLib:0x7f3209aaa450> 
    from /var/lib/gems/1.8/gems/actionpack-3.0.5/lib/action_view/helpers/capture_helper.rb:175:in `with_output_buffer' 
    from /var/lib/gems/1.8/gems/actionpack-3.0.5/lib/action_view/helpers/capture_helper.rb:40:in `capture' 
    from /var/lib/gems/1.8/gems/actionpack-3.0.5/lib/action_view/helpers/tag_helper.rb:77:in `content_tag' 
    from ./lib/my_lib.rb:6:in `foo' 
    from (irb):1 

Répondre

8

Y at-il une raison particulière, vous ne pouvez pas mettre cette logique dans une vue ? Content_tag a été créé pour l'environnement View et n'a pas été conçu pour être appelé à partir d'un contrôleur ou d'une autre bibliothèque. Vous devrez configurer votre classe MyLib en tant que vue. Bien que je vous recommande de repenser et de re-sentir votre code et votre design qui vous a amené à en avoir besoin, vous pouvez accomplir ce que vous voulez en sous-classant ActionView :: Base.

class MyLib < ActionView::Base 
    include ActionView::Helpers::TagHelper 

    def foo 
    content_tag :div do 
     "hello" 
    end 
    end 
end 
+0

Merci de poster ce –

-6
//my controller... 

function edit($id) { 

    // $this->form_validation->set_rules('phone', 'Phone', 'callback_Check_Phone'); 
    $this->form_validation->set_rules('email', 'Email', 'callback_Check_email'); 
    $this->form_validation->set_rules('uname', 'Uname', 'callback_Check_User'); 

    if ($this->form_validation->run() == TRUE) { 

     $hospitalid = $this->input->post("hospitalid"); 
     $hospitalname = $this->input->post("hospitalname"); 
     $doctorname = $this->input->post('docname'); 
     $babyname = $this->input->post('babyname'); 
     $sex = $this->input->post("sex"); 
     $weight = $this->input->post('weight'); 
     $parentname = $this->input->post('parentname'); 
     $address = $this->input->post("address"); 
     $email = $this->input->post('email'); 
     $phone = $this->input->post('phone'); 
     $username = $this->input->post("uname"); 
     $dob = $this->input->post('dob'); 
     $today_date = date("d-m-Y"); 

     $dateTimestamp1 = strtotime($today_date); 
     $dateTimestamp2 = strtotime($dob); 
     $this->session->set_userdata('pid', $id); 
     $id = $this->session->userdata('pid'); 
     $pass = $this->input->post('password'); 

     if ($dateTimestamp1 < $dateTimestamp2) { 

      $sess_id = $this->session->userdata('id'); 
      $this->session->set_flashdata('msg', 'Invalid Date of Birth'); 

      $result['query'] = $this->panel_model->hospitaldetails($sess_id); 
      $result['query1'] = $this->register_model->edit_patient($id); 
      $this->load->view('innerheader', $result); 
      $this->load->view('edit_patient', $result); 
     } else { 

      $sess_id = $this->session->userdata('id'); 


      $querys = $this->db->query("SELECT days FROM vaccine_details WHERE hospitalid='$sess_id'"); 
      if ($querys->result()) { 
       if (strcmp($pass , $phone)== 0) { 
        $items = array(); 
        $j = 0; 
        foreach ($querys->result() as $row1) { 
         $items[$j++] = $row1->days; 
        } 
        $Date = $dob; 
        $stamp = strtotime($Date); 
        $d = array(); 
        $i = 0; 
        foreach ($items as $day) { 
         $newstamp = $stamp + ($day * 24 * 60 * 60); 
         $d[$i++] = date("m/d/Y", $newstamp); 
         echo "<br>"; 
        } 
        $day = implode(',', $d); 
        $this->register_model->edit_patientdetails($id, $hospitalid, $hospitalname, $doctorname, $babyname, $sex, $weight, $parentname, $dob, $address, $email, $phone, $username, $day, $pass); 
        $this->session->set_flashdata('msg', 'succesfully updated'); 

        redirect('patient_register/patient_detail'); 
       } else { 


        $items = array(); 
        $j = 0; 
        foreach ($querys->result() as $row1) { 
         $items[$j++] = $row1->days; 
        } 
        $Date = $dob; 
        $stamp = strtotime($Date); 
        $d = array(); 
        $i = 0; 
        foreach ($items as $day) { 
         $newstamp = $stamp + ($day * 24 * 60 * 60); 
         $d[$i++] = date("m/d/Y", $newstamp); 
         echo "<br>"; 
        } 
        $day = implode(',', $d); 

        $this->register_model->edit_patientdetail($id, $hospitalid, $hospitalname, $doctorname, $babyname, $sex, $weight, $parentname, $dob, $address, $email, $phone, $username, $day); 
        echo $this->sendregistermsg($phone, $username); 
        echo $this->mail($email, $phone, $username); 

        $this->session->set_flashdata('msg', 'succesfully updated'); 

        redirect('patient_register/patient_detail'); 
       } 
      } else { 

       $querys = $this->db->query("SELECT days FROM vaccine_details WHERE hospitalid='admin'"); 
       if (strcmp($pass , $phone)== 0) { 
        $items = array(); 
        $j = 0; 
        foreach ($querys->result() as $row1) { 
         $items[$j++] = $row1->days; 
        } 
        $Date = $dob; 
        $stamp = strtotime($Date); 
        $d = array(); 
        $i = 0; 
        foreach ($items as $day) { 
         $newstamp = $stamp + ($day * 24 * 60 * 60); 
         $d[$i++] = date("m/d/Y", $newstamp); 
         echo "<br>"; 
        } 
        $day = implode(',', $d); 
        $this->register_model->edit_patientdetails($id, $hospitalid, $hospitalname, $doctorname, $babyname, $sex, $weight, $parentname, $dob, $address, $email, $phone, $username, $day, $pass); 
        echo $this->sendregistermsg($phone, $username); 
        echo $this->mail($email, $phone, $username); 

        $this->session->set_flashdata('msg', 'succesfully updated'); 

        redirect('patient_register/patient_detail'); 
       } else { 
        $items = array(); 
        $j = 0; 
        foreach ($querys->result() as $row1) { 
         $items[$j++] = $row1->days; 
        } 
        $Date = $dob; 
        $stamp = strtotime($Date); 
        $d = array(); 
        $i = 0; 
        foreach ($items as $day) { 
         $newstamp = $stamp + ($day * 24 * 60 * 60); 
         $d[$i++] = date("m/d/Y", $newstamp); 
         echo "<br>"; 
        } 
        $day = implode(',', $d); 
        $this->register_model->edit_patientdetail($id, $hospitalid, $hospitalname, $doctorname, $babyname, $sex, $weight, $parentname, $dob, $address, $email, $phone, $username, $day); 
        $this->session->set_flashdata('msg', 'succesfully updated'); 

        redirect('patient_register/patient_detail'); 
       } 
      } 
     } 
    } else { 
     $this->session->set_userdata('pid', $id); 
     $id = $this->session->userdata('pid'); 
     $this->session->set_flashdata('msg', 'Invalid Entry'); 
     $sess_id = $this->session->userdata('id'); 
     $result['query'] = $this->panel_model->hospitaldetails($sess_id); 
     $result['query1'] = $this->register_model->edit_patient($id); 
     $this->load->view('innerheader', $result); 
     $this->load->view('edit_patient', $result); 
     $this->load->view('footer', $result); 
    } 
} 
+1

Cela ne regarde même pas comme Ruby et encore moins Rails. – TJChambers