Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby/Rails cast as string error
    primarykey
    data
    text
    <p>i am using the parseexcel gem to read an excel file.. every thing is working fine as long as i am printing stuff to the console. i created a rake task to insert the data to the db.. so i have a bunch of create statements. like this </p> <pre><code>description = row[i+1].to_s Coa.create(:is_group =&gt; true, :ag_gl_code =&gt; "AGL_001", :description =&gt; "#{description}") </code></pre> <p>my problem is with the 'description' variable. its a string field. if i print description to the console like this it works and prints the value</p> <pre><code>puts "{#description}" #prints the value 'Estate' </code></pre> <p>but in the create it gives me an sql error</p> <pre><code>SQLite3::SQLException: unrecognized token: "'E": </code></pre> <p>but the query is generated fine. the string is in the query with a single quote, and if the replace the variable with a hard coded string it works just fine. i have tried many combinations, like using to_s etc.. but can't get it to work.</p> <p>any help would be appreciated. thanks</p> <p>here is my schema </p> <pre><code>create_table "coas", :force =&gt; true do |t| t.string "ag_gl_code" t.string "description" t.boolean "is_group" t.datetime "created_at" t.datetime "updated_at" end </code></pre> <p>here is the terminal log, i have logged the value of 'description', note that it prints the value, and no additional quotes.</p> <pre><code>Estate rake aborted! SQLite3::SQLException: unrecognized token: "'E": INSERT INTO "coas" ("created_at", "is_group" , "description", "ag_gl_code", "updated_at") VALUES ('2011-07-14 14:48:56.616150', 't', 'Estate', 'AGL_001', '2011-07-14 14:48:56.616150') </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload