Penny
Penny

Reputation: 157

PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type integer

I am getting this error in the Production site and this is the code in my views

<%= form_for [:admin, @course], :remote => true do |f| %>
  <%= f.label :name %>
  <%= f.text_field :name %>
  <%= f.label :duration %> 
  <%= f.number_field :duration, class: "input-md form-control mb-20"%> 
  <%= f.label :program_id %> 
  <%= f.collection_select :program_id, Program.where('id'), :id, :name, {}, {class: "input-md form-control mb-20" } %>
<%end%>

This works in my local server where i have sql db setup.

Program model
     has_many :courses 

can anyone guide me?

Upvotes: 0

Views: 5846

Answers (1)

Ritesh Ranjan
Ritesh Ranjan

Reputation: 1012

Where clause isn't calling anything to compare with, so PG doesn't know what to include in the results. A where clause must evaluate to true/false.

just replace

<%= f.collection_select :program_id, Program.where('id'), :id, :name, {}, {class: "input-md form-control mb-20" } %>

by

<%= f.collection_select :program_id, Program.all, :id, :name, {}, {class: "input-md form-control mb-20" } %>

If you have some problem with some of the Program in your data base, add a column as status in programs table and make changes here as

<%= f.collection_select :program_id, Program.where("status =?", true), :id, :name, {}, {class: "input-md form-control mb-20" } %>

Upvotes: 2

Related Questions