ruby-on-rails - Ruby on rails - 参数数量错误(2 为 1)[Rails]

标签 ruby-on-rails ruby database postgresql sqlite

我刚刚在我的 Ruby on Rails 中将我的数据库从 sqlite3 更改为 postgresql。

之前一切正常,但现在我在提交表单时遇到“错误数量的参数(2 对 1)”。我不明白为什么!

这里是我的代码:

我的 photo_controller 文件:

class PhotosController < ApplicationController
  before_action :set_photo, only: [:show, :edit, :update, :destroy]

  # GET /photos
  # GET /photos.json
  def index
    @photos = Photo.all 
  end

  # GET /photos/1
  # GET /photos/1.json
  def show
  end

  # GET /photos/new
  def new
    @photo = Photo.new
  end

  # GET /photos/1/edit
  def edit
  end

  # POST /photos
  # POST /photos.json
  def create
    @photo = Photo.new(photo_params)

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

  # PATCH/PUT /photos/1
  # PATCH/PUT /photos/1.json
  def update
    respond_to do |format|
      if @photo.update(photo_params)
        format.html { redirect_to @photo, notice: 'Photo was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @photo.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /photos/1
  # DELETE /photos/1.json
  def destroy
    @photo.destroy
    respond_to do |format|
      format.html { redirect_to photos_url }
      format.json { head :no_content }
    end
  end

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

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

我的 photo.rb 文件:

class Photo < ActiveRecord::Base
has_attached_file :image
end

我的 new.html.erb 文件(这是表格,在我选择图像并提交后,出现错误):

<h1>New photo</h1>


<%= form_for @photo, :html => { :multipart => true } do |f| %>
  <div class="field">
  <%= f.file_field :image %>
  </div>

  <div class="action">
  <%= f.submit %>
  </div>


<% end %>

我的 show.html.erb 文件:

<h1> Je viens de faire un upload ! </h1>



<% if @photo.image? %>

<!-- Load Feather code -->
<script type="text/javascript" src="http://feather.aviary.com/js/feather.js"></script>

<!-- Instantiate Feather -->
<script type='text/javascript'>
   var featherEditor = new Aviary.Feather({
       apiKey: '    f20374413e3ff5a8',
       apiVersion: 3,
       theme: 'light', // Check out our new 'light' and 'dark' themes!
       tools: 'all',
       appendTo: '',
       onSave: function(imageID, newURL) {
           var img = document.getElementById(imageID);
           img.src = newURL;
       },
       onError: function(errorObj) {
           alert(errorObj.message);
       }
   });
   function launchEditor(id, src) {
       featherEditor.launch({
           image: id,
           url: src
       });
      return false;
   }
</script>

<div id='injection_site'></div>

<img id='image1' src='<%= @photo.image.url %>'/>

<!-- Add an edit button, passing the HTML id of the image and the public URL of the image -->
<p><input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit photo' onclick="return launchEditor('image1', '<%= @photo.image.url %>');" /></p>
<% end %>

回溯:

Application trace : 
app/controllers/photos_controller.rb:27:in `create'

Full trace : 
activesupport (4.0.0) lib/active_support/callbacks.rb:78:in `run_callbacks'
paperclip (3.0.4) lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
paperclip (3.0.4) lib/paperclip/attachment.rb:382:in `post_process'
paperclip (3.0.4) lib/paperclip/attachment.rb:106:in `assign'
paperclip (3.0.4) lib/paperclip.rb:194:in `block in has_attached_file'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `public_send'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:42:in `_assign_attribute'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:29:in `block in assign_attributes'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `each'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:23:in `assign_attributes'
activerecord (4.0.0) lib/active_record/core.rb:192:in `initialize'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
activerecord (4.0.0) lib/active_record/inheritance.rb:27:in `new'
app/controllers/photos_controller.rb:27:in `create'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:413:in `_run__921501253494556441__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__2330035833412540959__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/ubuntu/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

请帮帮我 :)

最佳答案

看起来你看到了 this error您应该将 Paperclip 升级到最新版本 3.5.2

无论如何,你运行的是一个相当旧的回形针。

关于ruby-on-rails - Ruby on rails - 参数数量错误(2 为 1)[Rails],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20271345/

相关文章:

ruby-on-rails - Ruby on Rails Youtube图像嵌入

mysql - 连接后 2 个表的乘积的别名

ruby-on-rails - 如何在集成测试中检查正在进行的 AJAX 调用的数量?

ruby-on-rails - Activerecord 的 Rails Domain 模型解耦

ruby-on-rails - 为什么此测试失败 - 未实现错误 Rspec 3.1.x 和 Rails 4.1.9

ruby - 如何完全停止 Whenever Cron 作业?

php - MySQL PHP - substr() 导致在空表单字段上将 0 个零输入到数据库中

database - 调试时如何在 TOAD 中查看 CLOB 变量的完整值

php - 带有wordpress作为子文件夹的Rails heroku应用程序,无法登录到管理员

ruby-on-rails - 升级rails 2.3后在集成测试中设置多个cookie会导致NoMethodError