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_personas
(apellido_mat
,apellido_pat
,centro_trabajo
,ciudadania
,ciudadania2_id
,ciudadania_id
,direccion
,created_at
,direccion
,documento_ident_id
,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“=> “创造人格”}
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
,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
最满意答案
不,没有特权。
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';
相关问答
更多-
如何在Oracle中找到授予用户的权限和角色?(How to find the privileges and roles granted to a user in Oracle?)[2023-01-19]
看http://docs.oracle.com/cd/B10501_01/server.920/a96521/privs.htm#15665 检查USER_SYS_PRIVS,USER_TAB_PRIVS,USER_ROLE_PRIVS表。 Look at http://docs.oracle.com/cd/B10501_01/server.920/a96521/privs.htm#15665 Check USER_SYS_PRIVS, USER_TAB_PRIVS, USER_ROLE_PRIVS tab ... -
首先,通过OS的命令连接到SYS模式 $> sqlplus / as sysdba (这意味着隐式连接到SYS模式) 然后,查询您的架构是否存在 SQL>select * from dba_users where user_name = 'MYSCHEMA' 如果没有使用此命令创建一个SQL>创建由mypasswd标识的用户myschema; 并使用此权限授予此新创建的架构, SQL>grant connect to myschema; SQL>grant resource to myschema; S ...
-
默认情况下,jbpm-installer使用UserGroupCallback来查找使用JAAS的有效用户,因此它委派给应用程序服务器身份验证。 使用user.properties和roles.properties时,如果不重新启动服务器,则不支持动态更新这些文件,但仅用于演示目的。 重新配置安全域以获取更多高级选项。 By default the jbpm-installer uses a UserGroupCallback that looks up valid users using JAAS, so ...
-
您应该将LoginCreatedUser设置为false以禁用自动登录。 You should set LoginCreatedUser to false to disable auto-login.
-
您的命令with encrypted password 'asdf';指定with encrypted password 'asdf'; 加密到asdf的明文密码不是asdf 。 您需要with unencrypted password进行specife或计算加密值。 psql中的\password命令最好使用。 此外,您需要在pg_hba.conf文件中指定允许密码验证; 除非您是超级用户,否则默认情况下(我相信)仅将您作为unix用户进行身份验证。 Your command specified with ...
-
尽管此问题更适合超级用户,但您的命令似乎并未为Trainee创建管理员帐户。 要做到这一点,您需要以管理员身份使用: net user /add Trainee Pa55_W0rd net localgroup administrators Trainee /add 另外我猜想新用户需要登录才能执行他们的目录结构和帐户设置。 在那之前,无处可复制任何东西。 The answer is this can't be done, at least with a batch file. The problem i ...
-
不,没有特权。 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_ ...
-
在mysql.user表中创建一个新行,并为该帐户分配无权限http://dev.mysql.com/doc/refman/5.1/en/create-user.html creates a new row in the mysql.user table and assigns the account no privileges http://dev.mysql.com/doc/refman/5.1/en/create-user.html
-
有一种方法可以使用group资源修改sudo组: group "create testuser sudo" do group_name 'sudo' members 'testuser' action :modify append true end 另一种方法是使用sudo recipe https://supermarket.chef.io/cookbooks/sudo 。 对我来说推荐的方法是使用sudo配方,并将系统特定的逻辑卸载到配方中。 在那里你可以获得属性资源配置,使你的配方代 ...
-
无法写入新创建的文件(Cant write to newly created files)[2022-10-07]
你的分数很可能是满的。 执行df -h并检查是否有任何分区的使用百分比达到100% Your parition is most probably full. do df -h and check if any partitions' Use% have hit 100%