почему, когда я загружаю изображение с использованием carrierwave в rails 4, происходит откат базы данных?
я пытаюсь сохранить файл изображения с помощью carrierwave в rails 4, но когда кнопка «Отправить» нажата, база данных отката ??? Почему ?
Если я не выбираю изображение для загрузки и просто отправляю только строку, все работает правильно, но если я отправляю файл изображения, я получаю ошибку, подобную этой:
TypeError: can't cast ActionDispatch::Http::UploadedFile to string: INSERT INTO "items" ("created_at", "description", "image", "name", "store_id", "sub_items", "title", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?)
(0.2ms) rollback transaction
*** ActiveRecord::StatementInvalid Exception: TypeError: can't cast ActionDispatch::Http::UploadedFile to string: INSERT INTO "items" ("created_at", "description", "image", "name", "store_id", "sub_items", "title", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?)
мой вид :
<%= form_for @items, :url => dashboard_create_items_path(@store.id), :html => {:multipart => true} do |f| %>
<%= f.label :name, 'Name' %>
<%= f.text_field :name %><br />
<%= f.label :title, 'Title' %>
<%= f.text_field :title %><br />
<%= f.label :image, 'Image' %>
<%= f.file_field :image %><br />
<%= f.label :description, 'Description' %>
<%= f.text_field :description %><br />
<%= f.label :sub_items %><br>
<%= f.select :sub_items, options_for_select([["true", true], ["false", false]]), :selected => 'true' %><br />
<%= f.submit %>
<% end %>
мой контроллер:
def create_items
store = Store.find(params[:id])
@items = store.items.create(item_params)
if @items
redirect_to dashboard_show_items_url(@items.id, store.id)
else
redirect_to dashboard_new_items_url
end
end
private
def item_params
params.require(:item).permit(:name, :title, :image, :description, :sub_items, :store_id)
end
пожалуйста, скажите мне, когда я ошибаюсь? спасибо, прежде чем