2013-06-22 34 views
1

我正在爲一家醫院的西班牙系統工作。 我得到了一個名爲角色的腳手架。Params不會傳遞給對象?

在我的控制器中,我得到了一個「新」和「創建」的方法,就像幾乎一樣。 我可以到new_persona視圖(帶表單)並輸入一些數據。問題是現在,當我要創造我所插入的人,我得到以下錯誤:

"ActiveRecord::StatementInvalid in Hds::PersonasController#create"

此外,它說我2列不能爲空。當然,我得到的空值應該是錯誤的mysql選項,因爲我不希望這2列有空。 問題是即使當我在這些字段中插入某些內容時,導軌也會增加此錯誤。 希望你能理解我並能幫助我。下面的代碼:

personas_controller新創建:

def new 
    @persona = Hds::Persona.new 



    respond_to do |format| 
    format.html # new.html.erb 
    format.json { render json: @persona } 
    end 
end 


def create 
    @persona = Hds::Persona.new(params[:persona]) 

    respond_to do |format| 
     if @persona.save! 
     format.html { redirect_to @persona, notice: 'Persona was successfully created.' } 
     format.json { render json: @persona, status: :created, location: @persona } 
     else 
     format.html { render action: "new" } 
     format.json { render json: @persona.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

形式:

<%= form_for(@persona, :validate=>true) do |f| %> 
    <% if @persona.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@persona.errors.count, "error") %> prohibited this persona from being saved:</h2> 

     <ul> 
     <% @persona.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

<table class="form_table"> 
    <tr class="partial_head"> 
    <th colspan="2"> 
     <h3>Datos personales</h3> 
    </th> 
    </tr> 

    <tr> 
     <div class="field"> 
     <td><%= f.label :numero_doc %></td> 
     <td><%= f.text_field :numero_doc %></td> 
     </div> 
    </tr> 


[...] 

</table> 

f.submit 

<% end %> 

感謝您的幫助! 問候, CO

這裏完整的錯誤消息:

Mysql2::Error: Column 'apellido_pat' cannot be null: INSERT INTO hds_personas (apellido_mat , apellido_pat , centro_trabajo , ciudadania , ciudadania2_id , ciudadania_id , conctacto , created_at , direccion , documento_ident_id , email , estado_cd , estado_civil_cd , estudio_id , fecha_defuncion , fecha_nacimiento , nombre_comercial , nombres , nro_hijos , numero_doc , ocupacion , ocupacion_id , origen_etnico_cd , profesion , profesion_id , razon_social , religion_cd , religion_string , representante , ruc , servicio_basico_gral_id , sexo_cd , telf_contacto , telf_fijo , telf_movil , tipo_documento_cd , ubigeo_direccion_id , ubigeo_nacimiento_id , updated_at) VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2013-06-24 07:39:24', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2013-06-24 07:39:24')

這裏的參數:

{"utf8"=>"✓", "authenticity_token"=>"VYHiP9/zLNjZ0ElAFh1IeC4s5X5oxVFFhpbmbK2oVAs=", "hds_persona"=>{"numero_doc"=>"", "sexo"=>"masculino", "nombres"=>"test", "apellido_pat"=>"test", "apellido_mat"=>"", "direccion"=>"", "fecha_nacimiento"=>"", "estado_civil"=>"soltero", "nro_hijos"=>"", "telf_movil"=>"", "email"=>"", "ubigeo_direccion_id"=>"", "ubigeo_nacimiento_id"=>"", "ciudadania_id"=>"", "ciudadania2_id"=>"", "origen_etnico"=>"asiatico", "religion"=>"catolico", "estudio_id"=>"", "ocupacion_id"=>"", "profesion_id"=>""}, "commit"=>"Create Persona"}

+0

什麼是Hds :: Persona.new()????你可以試試這個Persona.new() –

+0

你能發佈完整的錯誤嗎?和列名? –

+0

Hds :: Persona是我的課程。 Hds是我在這種情況下得到的命名空間。如果我嘗試沒有Hds,我會得到「未初始化的常量Hds :: PersonasController :: Persona」。我上面發佈了完整的錯誤,在我的錯誤列表中列出了柱面名稱。 –

回答

0

我得到了它,它應該是

params[:hds_persona]

我創造法。

謝謝!