2013-06-22 32 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]

我创造法。

谢谢!