Я новичок в Ruby и Ruby on Rails.
Я создаю пример приложения (без использования скаффолдинга) для вставки строки в таблицу.Таблица имеет 2 столбца, «имя» и «описание» (вместе с 3 волшебными столбцами).
На мой взгляд, у меня есть нечто, похожее на это:
<h1>New Location</h1>
<%= form_for(@location) do |l| %>
<div class="field">
<%= l.label :name %><br />
<%= l.text_field :name %>
</div>
<div class="field">
<%= l.label :description %><br />
<%= l.text_field :description %>
</div>
<div class="actions">
<%= l.submit "Add" %>
</div>
И контроллер:
class LocationsController < 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
Код модели:
class Location < ActiveRecord::Base
attr_accessible :name, :description
has_many :foods
end
Это то, что печатает консоль:
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"=>"Add", "location"=>{"name"=>"name", "description"=>"description"}, "authenticity_token"=>"7rT1/3qSn/Kz1cGg8iTFCKbkO0W/L7ETT+lNcSSN6FI=", "utf8"=>"\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)
tl; dr: вызов .save завершается ошибкой и возвращает SQLite3:: SQLException: не удается запустить транзакцию внутри транзакции: начать транзакцию