Ruby on rails 回形针不';t将图像插入数据库(Rails 4和回形针4.2.1)

Ruby on rails 回形针不';t将图像插入数据库(Rails 4和回形针4.2.1),ruby-on-rails,ruby,paperclip,Ruby On Rails,Ruby,Paperclip,当我试图通过回形针将图像上传到数据库时,它总是忽略图像列。我不知道为什么它不起作用,我做了很多关于回形针的研究,例如,做了与那些教程完全相同的研究。我想我所有的代码都是正确的,但我不知道问题出在哪里,请指出 控制台信息 Started POST "/categories" for 127.0.0.1 at 2015-04-13 17:07:49 +1000 Processing by CategoriesController#create as HTML Parameters: {"utf8"=

当我试图通过回形针将图像上传到数据库时,它总是忽略图像列。我不知道为什么它不起作用,我做了很多关于回形针的研究,例如,做了与那些教程完全相同的研究。我想我所有的代码都是正确的,但我不知道问题出在哪里,请指出

控制台信息

Started POST "/categories" for 127.0.0.1 at 2015-04-13 17:07:49 +1000
Processing by CategoriesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"DIR1d3lWrcwcylkelLsRm/262BRZqu5w3cmrMP/5LV0=", "category"=>{"name"=>"Food", "parent_category_id"=>"", "description"=>""}, "commit"=>"Create Category"}
(0.1ms)  begin transaction
SQL (0.4ms)  INSERT INTO "categories" ("created_at", "description", "name", "updated_at") VALUES (?, ?, ?, ?)  [["created_at", "2015-04-13 07:07:49.850360"], ["description", ""], ["name", "Food"], ["updated_at", "2015-04-13 07:07:49.850360"]]
(9.3ms)  commit transaction
Redirected to http://localhost:3000/categories/1
Completed 302 Found in 15ms (ActiveRecord: 9.7ms)
Gemfile

source 'https://rubygems.org'


gem 'rails', '4.1.6'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc

gem 'spring',        group: :development
gem 'paperclip', '~> 4.2.1'
gem 'bootstrap-sass'

gem 'jquery_mobile_rails'
模范班

class Category < ActiveRecord::Base
  has_attached_file :photo, :styles => {:medium => "300x300", :thumb => "100x100"}
  validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/

  has_many :children, class_name: "Category", foreign_key: "parent_category_id"
  belongs_to :parent, class_name: "Category", foreign_key: "parent_category_id"

  #has_many :products
end
像这样更改了_form.html.erb文件

<%= form_for @category, :url => categories_path, :html => {:multipart => true} do |f| %>
    ...
<div class="field">
   <%= f.label :photo %><br>
   <%= f.file_field :photo %>
</div>
    ...
问题已从解决,希望这将帮助有相同问题的人

我认为问题是由使用jquery\u mobile\u rails gem引起的,我需要像这样更改_form.html.erb文件(添加“data ajax”=>false)


你为什么只把宝石列入开发组?是吗?我认为只有创业板“春天”被纳入开发组。我把回形针的位置改到了文件的顶部,结果没有改变。这与回形针无关。您的参数中没有图像属性。我不认为你真的需要
:url=>categories\u path
,但这与你的问题无关,只是一个提示。我尝试了不同的方法解决这个问题,但无法解决。。
<%= form_for @category, :url => categories_path, :html => {:multipart => true} do |f| %>
    ...
<div class="field">
   <%= f.label :photo %><br>
   <%= f.file_field :photo %>
</div>
    ...
create_table "categories", force: true do |t|
    t.string   "name"
    t.integer  "parent_category_id"
    t.text     "description"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "photo_file_name"
    t.string   "photo_content_type"
    t.integer  "photo_file_size"
    t.datetime "photo_updated_at"
end
= form_for(@category, :html => { :multipart => true, "data-ajax" => false}) do |f|