简体   繁体   English

Ruby或Rails:PG数据查询错误,

[英]Ruby or Rails: PG Data Query Error,

I'm trying to update a few records based on a user entered string - it won't let me and produces this error: 我正在尝试根据用户输入的字符串来更新一些记录-它不会让我产生此错误:

PGError: ERROR:  invalid input syntax for type boolean: "ian"
LINE 1: UPDATE "subjects" SET treatment_group = 'ian' AND pref_rand ...

I double checked the type from the rails console: 我从Rails控制台再次检查了类型:

Subject.column_hash["treatment_group"].type
=> :string

And the input method is: 输入方法为:

Group Name: <%= text_field_tag(:treatment_group_name) %>

Finally, within the controller I have this logic: 最后,在控制器中,我有以下逻辑:

@group_to_randomize = Subject.where("study_site = ? AND treatment_group is null", params[:site_input].to_i).order("created_at ASC").limit(params[:group_size_input].to_i)

      flash[:notice] = "We are at the database level. #{@group_to_randomize.inspect}"
      if params[:treatment_group_name] != '' and params[:site_input] != '' and params[:group_size_input] != ''
        @group_to_randomize.update_all(["treatment_group = ? AND pref_rand = ?", params[:treatment_group_name, @treatment.to_i])
        flash[:notice] = "Subjects randomized, and assigned to group #{params[:treatment_group_name]}"
      else
        flash[:notice] = "Nothing saved, please fill in the form completely."
      end

So that it's easier to read, the error stems from this line: 为了更容易阅读,错误源于此行:

@group_to_randomize.update_all(["treatment_group = ? AND pref_rand = ?", params[:treatment_group_name], @treatment.to_i])

So I can't figure out why it thinks the input is a boolean, and why it won't save as a string anyway. 因此,我无法弄清为什么它认为输入是布尔值,以及为什么无论如何它都不会保存为字符串。 Any help would be greatly appreciated. 任何帮助将不胜感激。

由于语法错误,请修改此行

@group_to_randomize.update_all(treatment_group:params[:treatment_group_name], pref_rand: @treatment.to_i)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM