首页 \ 问答 \ Params没有传递给对象?(Params dont get passed to the object?)

Params没有传递给对象?(Params dont get passed to the object?)

我正在为医院制作西班牙语系统。 我有一个名为persona的脚手架。

在我的控制器中,我得到了一个“新”和“创建”方法,就像几乎所有。 我可以进入new_persona视图(带表单)并输入一些数据。 问题是现在,当我想创建我插入的人时,我收到以下错误:

“Hds :: PersonasController #create中的ActiveRecord :: StatementInvalid”

此外,它告诉我2列不能为空。 当然,我得到了null应该为false的mysql-option,因为我不希望这2列永远是空的。 问题是,即使我在这些字段中插入了某些内容,rails也会出现此错误。 希望你了解我,可以帮助我。 这里的代码:

personas_controller new和create:

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 ::错误:列'apellido_pat'不能为空:INSERT INTO hds_personasapellido_matapellido_patcentro_trabajociudadaniaciudadania2_idciudadania_iddireccioncreated_atdirecciondocumento_ident_idemailestado_cdestado_civil_cdestudio_idfecha_defuncionfecha_nacimientonombre_comercialnombresnro_hijosnumero_dococupacionocupacion_idorigen_etnico_cdprofesionprofesion_idrazon_socialreligion_cdreligion_stringrepresentanterucservicio_basico_gral_idsexo_cdtelf_contactotelf_fijotelf_moviltipo_documento_cdubigeo_direccion_idubigeo_nacimiento_idupdated_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“=> “创造人格”}


i'm working on a spanish system for a hospital. I got a scaffold named persona.

Well in my controller i got a "new" and a "create" method, like almost always. I can get to the new_persona view (with form) and enter some datas. The problem is now, when i want to create the person i've inserted, i get the following error:

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

Furthermore it says me that 2 columns cant be null. Sure, i got the mysql-option that null should be false, because i dont want this 2 columns ever to be empty. The problem is that rails rises this error even when i inserted something in those fields. Hope you understand me and can help me. Here the code:

personas_controller new and create:

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:

<%= 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 %>

Thanks for the help!! Greetings, CO

Here the full error message:

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')

And here the parameters:

{"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"}


原文:https://stackoverflow.com/questions/17254017
更新时间:2023-05-10 22:05

最满意答案

不,没有特权。

select * from dba_sys_privs where grantee='JOHN';

select * from dba_tab_privs where grantee='JOHN';

select * from dba_role_privs where grantee='JOHN';

Nope, no privileges.

select * from dba_sys_privs where grantee='JOHN';

select * from dba_tab_privs where grantee='JOHN';

select * from dba_role_privs where grantee='JOHN';

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。