Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails-参数数目错误(2对1)[rails]_Ruby On Rails_Ruby_Database_Postgresql_Sqlite - Fatal编程技术网

Ruby on rails RubyonRails-参数数目错误(2对1)[rails]

Ruby on rails RubyonRails-参数数目错误(2对1)[rails],ruby-on-rails,ruby,database,postgresql,sqlite,Ruby On Rails,Ruby,Database,Postgresql,Sqlite,我刚刚在RubyonRails中将数据库从sqlite3更改为postgresql 以前每件事都是有效的,但现在我在提交表单时遇到了“错误数量的参数(2对1)”。我不明白为什么 这是我的代码: 我的照片控制器文件: class PhotosController < ApplicationController before_action :set_photo, only: [:show, :edit, :update, :destroy] # GET /photos # GET

我刚刚在RubyonRails中将数据库从sqlite3更改为postgresql

以前每件事都是有效的,但现在我在提交表单时遇到了“错误数量的参数(2对1)”。我不明白为什么

这是我的代码:

我的照片控制器文件:

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

请帮帮我:)

只需从上面拉出基本部件:

错误:

wrong number of arguments (2 for 1)
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'
来源:

wrong number of arguments (2 for 1)
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'
控制器:

1: class PhotosController < ApplicationController
...
24: # POST /photos
25: # POST /photos.json
26: def create
27:  @photo = Photo.new(photo_params)
看起来您看到了,您应该将回形针升级到最新版本,
3.5.2


无论如何,你正在运行一个非常旧的回形针。

如果没有堆栈跟踪,就不可能找出错误。好的,我把它添加到问题中,哪一行是
app/controllers/photos\u controller.rb:27:in'create'
它是@photo=photo.new(photo\u params)发布
photo\u params
的值。我不想编辑上面的帖子,因为这是一个相当自由的重写。我相信这些是最基本的信息。非常感谢,就是这样!我遵循了一个旧的教程,我不知道为什么它有时有效,有时无效!
1: class PhotosController < ApplicationController
...
24: # POST /photos
25: # POST /photos.json
26: def create
27:  @photo = Photo.new(photo_params)
class Photo < ActiveRecord::Base
  has_attached_file :image
end
<%= form_for @photo, :html => { :multipart => true } do |f| %>
  <div class="field">
    <%= f.file_field :image %>
  </div>

  <div class="action">
    <%= f.submit %>
  </div>    
<% 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'