rails 4中的ArgumentError(参数太少)仅用于生产(heroku)环境的respond_to调用

时间:2014-10-02 17:20:08

标签: ruby-on-rails ruby heroku dragonfly-gem

将新照片发布到控制器时出现以下错误。我只有生产中的错误,在本地它工作正常。我查看了参数并且在本地看起来相同,只有UTF8参数在本地有不同的字符。

enter image description here

我的控制器是。第35行正好是respond_to do |format|

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

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

我的模特是

class Photo < ActiveRecord::Base
  dragonfly_accessor :image
  belongs_to :user

  validates :image, presence: true
  validates_size_of :image, maximum: 500.kilobytes,
    message: "should be no more than 500 KB", if: :image_changed?

  validates_property :format, of: :image, in: [:jpeg, :jpg, :png, :bmp], case_sensitive: false,
    message: "should be either .jpeg, .jpg, .png, .bmp", if: :image_changed?
end

Dragonfly配置

require 'dragonfly'

# Configure
Dragonfly.app.configure do
  protect_from_dos_attacks true
  secret "92a3093304fd5b5ad0d1fa716caeae7b02aedd702127ead467f24f6b1526bd05"

  url_format "/media/:job/:name"

  Rails.logger.debug 'Root path: ' + Rails.root.join('public/system/dragonfly', Rails.env).inspect
  if Rails.env.development? || Rails.env.test?
   plugin :imagemagick,
     convert_command: 'C:/Ruby200-x64/ImageMagic/convert',    # defaults to "convert"
     identify_command: 'C:/Ruby200-x64/ImageMagic/identify'  # defaults to "identify"
  else
#    datastore :s3,
#      bucket_name: 'petowners',
#      access_key_id: 'insert_key',
#      secret_access_key: 'insert_key',
#      url_scheme: 'https'
  end
    datastore :file,
      root_path: Rails.root.join('public/system/dragonfly', Rails.env),
      server_root: Rails.root.join('public')
end

# Logger
Dragonfly.logger = Rails.logger

# Mount as middleware
Rails.application.middleware.use Dragonfly::Middleware

# Add model functionality
if defined?(ActiveRecord::Base)
  ActiveRecord::Base.extend Dragonfly::Model
  ActiveRecord::Base.extend Dragonfly::Model::Validations
end

我的路线是

  resources :pets
  resources :dogs, controller: 'pets', type: 'Dog' 
  resources :hamsters, controller: 'pets', type: 'Hamster' 
  resources :cats, controller: 'pets', type: 'Cat'

  authenticated :user do
    root 'users#newsfeed', :as => :authenticated_root
    get '/profile/:id', :to => 'users#profile', :as => :user_profile
  end
  root to: 'visitors#index'
  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
  resources :users
  resources :photos, only: [:new, :create]
  get '/photos/new_multiple', to: 'photos#new_multiple', as: :new_photo_multiple

我正在使用具有相同datatstore的dragonfly。 Rails 4.1.6

1 个答案:

答案 0 :(得分:0)

我删除了

protect_from_dos_attacks true

并且有效