表单输入不会创建记录

时间:2014-04-11 20:38:28

标签: ruby-on-rails forms sqlite haml

我正在使用回形针和保管箱进行图像处理。

我不知道为什么我会这样做。我尝试解决sqlite3繁忙异常错误的一些解决方案并不起作用。

但我也怀疑我的参数在某种程度上是不正确的...... 控制器指定我需要一个角色对象,但参数似乎没有。我知道我使用了一个名为:image的文件附件,但是一旦图像上传并提交了表单,paperclip,imagemagick和dropbox就会处理图像属性的创建。


这是我在浏览器中收到的错误。

enter image description here

形式:     = form_for(@character,:html => {:multipart => true})do | f |

- if @character.errors.any?
    #error_explanation
        %h2= "#{pluralize(@character.errors.count, "error")} prohibited this character from being saved:"
        %ul
            - @character.errors.full_messages.each do |msg|
                %li= msg

#stripe_error.alert.alert-danger{ :style => "display:none" }
    %noscript JavaScript is not enabled and is required for this form. First enable it in your web browser settings.

.form-group
    = f.label :name
    = f.text_field :name
.form-group
    = f.label :image
    = f.file_field :image   
.action
    = f.submit

控制器:

def create
@character = Character.new(character_params)

respond_to do |format|
  if @character.save
    format.html { redirect_to @character, notice: 'Character was successfully created.' }
    format.json { render action: 'show', status: :created, location: @character }
  else
    format.html { render action: 'new' }
    format.json { render json: @character.errors, status: :unprocessable_entity }
  end
end
end

...

private
# Use callbacks to share common setup or constraints between actions.
def set_character
  @character = Character.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def character_params
  params.require(:character).permit(:name, :image)
end
end

Gemfile:(是的,捆绑安装)

    source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more:     
https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use Haml for views
gem 'haml-rails'
gem 'bootstrap-sass', "~> 3.0.3.0"
gem 'paperclip', "~> 3.0"
gem 'paperclip-dropbox', ">= 1.1.7"



group :development do

    gem 'nokogiri'

    #gem 'hpricot', '0.8.6'


gem 'ruby_parser', '~> 3.1.1'

# erubis is already included in action pack
    gem 'html2haml'
end

group :development, :test do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

0 个答案:

没有答案