Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby/Rails: Can't get controller to insert new value into DB
    primarykey
    data
    text
    <p>I'm new to Ruby and Ruby on Rails.</p> <p>I'm making a sample app (not using scaffolding) to insert a row into a table. Table has 2 columns, "name" and "description" (along with the 3 magic columns).</p> <p>In my view, I have something that looks like this:</p> <pre><code>&lt;h1&gt;New Location&lt;/h1&gt; &lt;%= form_for(@location) do |l| %&gt; &lt;div class="field"&gt; &lt;%= l.label :name %&gt;&lt;br /&gt; &lt;%= l.text_field :name %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= l.label :description %&gt;&lt;br /&gt; &lt;%= l.text_field :description %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= l.submit "Add" %&gt; &lt;/div&gt; </code></pre> <p>And controller:</p> <pre><code>class LocationsController &lt; ApplicationController def new @location = Location.new end def create @location = Location.new(params[:location]) @location.save #fails on this line redirect_to @location end end </code></pre> <p>Model code:</p> <pre><code>class Location &lt; ActiveRecord::Base attr_accessible :name, :description has_many :foods end </code></pre> <p>This is what the console prints out:</p> <pre><code>Started POST "/locations" for 127.0.0.1 at Wed Jan 25 17:09:22 -0500 2012 Processing by LocationsController#create as HTML Parameters: {"commit"=&gt;"Add", "location"=&gt;{"name"=&gt;"name", "description"=&gt;"description"}, "authenticity_token"=&gt;"7rT1/3qSn/Kz1cGg8iTFCKbkO0W/L7ETT+lNcSSN6FI=", "utf8"=&gt;"\342\234\223"} (0.1ms) begin transaction SQL (5081.3ms) INSERT INTO "locations" ("created_at", "description", "name", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Wed, 25 Jan 2012 22:09:22 UTC +00:00], ["description", "description"], ["name", "name"], ["updated_at", Wed, 25 Jan 2012 22:09:22 UTC +00:00]] SQLite3::BusyException: database is locked: INSERT INTO "locations" ("created_at", "description", "name", "updated_at") VALUES (?, ?, ?, ?) (0.2ms) rollback transaction SQLite3::BusyException: cannot rollback transaction - SQL statements in progress: rollback transaction Completed 500 Internal Server Error in 5084ms ActiveRecord::StatementInvalid (SQLite3::BusyException: cannot rollback transaction - SQL statements in progress: rollback transaction): app/controllers/locations_controller.rb:8:in `create' Rendered /Library/Ruby/Gems/1.8/gems/actionpack 3.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.8ms) Rendered /Library/Ruby/Gems/1.8/gems/actionpack 3.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms) Rendered /Library/Ruby/Gems/1.8/gems/actionpack 3.2.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (3.9ms) </code></pre> <p>tl;dr: calling .save fails and returns SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction</p>
    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