当我尝试在我的应用中使用图片创建列表时,会抛出此错误:
undefined method `call' for "result == false":String.
安装devise gem后发生错误。但设计不应该与创建新的列表有任何关系吗?
该应用程序的其他部分工作正常,我可以创建没有图像的新列表。
错误消息
NoMethodError in ArtistsController#create
undefined method `call' for "result == false":String
它指向的方法是ActiveSupport中的回调方法,位于第164行
任何人都有任何想法可能是什么问题?我对此非常陌生,所以如果您需要我提供更多信息或者我需要重新解释我的问题,请告诉我。
的Gemfile
source 'https://rubygems.org'
ruby "2.0.0"
gem 'rails', '4.2.0.beta2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'bootstrap-sass', '~> 3.3.0'
gem 'sass-rails', '~> 5.0.0.beta1'
gem "paperclip", "~> 3.0"
gem "paperclip-dropbox", ">= 1.1.7"
gem "figaro"
gem 'devise'
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development, :test do
gem 'sqlite3'
end
group :doc do
gem 'sdoc', require: false
end
Artists_controller,控件中的create方法似乎抛出异常
class ArtistsController < ApplicationController
before_action :set_artist, only: [:show, :edit, :update, :destroy]
# GET /artists
# GET /artists.json
def index
@artists = Artist.all
end
# GET /artists/1
# GET /artists/1.json
def show
end
# GET /artists/new
def new
@artist = Artist.new
end
# GET /artists/1/edit
def edit
end
# POST /artists
# POST /artists.json
def create
@artist = Artist.new(artist_params)
respond_to do |format|
if @artist.save
format.html { redirect_to @artist, notice: 'Artist was successfully created.' }
format.json { render action: 'show', status: :created, location: @artist }
else
format.html { render action: 'new' }
format.json { render json: @artist.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /artists/1
# PATCH/PUT /artists/1.json
def update
respond_to do |format|
if @artist.update(artist_params)
format.html { redirect_to @artist, notice: 'Artist was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @artist.errors, status: :unprocessable_entity }
end
end
end
# DELETE /artists/1
# DELETE /artists/1.json
def destroy
@artist.destroy
respond_to do |format|
format.html { redirect_to artists_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_artist
@artist = Artist.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def artist_params
params.require(:artist).permit(:name, :description, :price, :image)
end
end
用户类
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
艺术家类(列表型号)
class Artist < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url
=> "/images/:style/missing.png"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end
表单助手
<%= form_for(@artist, :html => { :multipart => true }) do |f| %>
<% if @artist.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@artist.errors.count, "error") %> prohibited this artist from being saved:</h2>
<ul>
<% @artist.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<%= f.label :name %><br>
<%= f.text_field :name, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :description %><br>
<%= f.text_field :description, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :price %><br>
<%= f.text_field :price, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :image %><br>
<%= f.file_field :image, class: "form-control" %>
</div>
<div class="actions">
<%= f.submit class: "btn btn-primary" %>
</div>
<% end %>
完整跟踪
app/controllers/artists_controller.rb:27:in `create'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:161:in `block in halting'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:87:in `call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:87:in `run_callbacks'
paperclip (3.5.4) lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
paperclip (3.5.4) lib/paperclip/attachment.rb:419:in `block in post_process'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:83:in `run_callbacks'
paperclip (3.5.4) lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
paperclip (3.5.4) lib/paperclip/attachment.rb:418:in `post_process'
paperclip (3.5.4) lib/paperclip/attachment.rb:112:in `assign'
paperclip (3.5.4) lib/paperclip/has_attached_file.rb:65:in `block in define_setter'
activerecord (4.2.0.beta2) lib/active_record/attribute_assignment.rb:54:in `public_send'
activerecord (4.2.0.beta2) lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
activerecord (4.2.0.beta2) lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
actionpack (4.2.0.beta2) lib/action_controller/metal/strong_parameters.rb:170:in `each_pair'
actionpack (4.2.0.beta2) lib/action_controller/metal/strong_parameters.rb:170:in `each_pair'
activerecord (4.2.0.beta2) lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
activerecord (4.2.0.beta2) lib/active_record/core.rb:551:in `init_attributes'
activerecord (4.2.0.beta2) lib/active_record/core.rb:272:in `initialize'
activerecord (4.2.0.beta2) lib/active_record/inheritance.rb:61:in `new'
activerecord (4.2.0.beta2) lib/active_record/inheritance.rb:61:in `new'
actionpack (4.2.0.beta2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0.beta2) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0.beta2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0.beta2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:114:in `call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:114:in `call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:148:in `block in halting_and_conditional'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:231:in `call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:231:in `block in halting'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:231:in `call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:231:in `block in halting'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:87:in `call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:87:in `run_callbacks'
actionpack (4.2.0.beta2) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0.beta2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0.beta2) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0.beta2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.beta2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.beta2) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0.beta2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0.beta2) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0.beta2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0.beta2) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0.beta2) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0.beta2) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0.beta2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0.beta2) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0.beta2) lib/action_dispatch/routing/route_set.rb:72:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/routing/route_set.rb:72:in `dispatch'
actionpack (4.2.0.beta2) lib/action_dispatch/routing/route_set.rb:41:in `serve'
actionpack (4.2.0.beta2) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0.beta2) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0.beta2) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0.beta2) lib/action_dispatch/routing/route_set.rb:750:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0.beta) lib/rack/etag.rb:23:in `call'
rack (1.6.0.beta) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.0.beta) lib/rack/head.rb:13:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/flash.rb:257:in `call'
rack (1.6.0.beta) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0.beta) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/cookies.rb:558:in `call'
activerecord (4.2.0.beta2) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0.beta2) lib/active_record/connection_adapters/abstract/connection_pool.rb:645:in `call'
activerecord (4.2.0.beta2) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0.beta2) lib/active_support/callbacks.rb:83:in `run_callbacks'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0.beta2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0.beta2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0.beta2) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0.beta2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0.beta2) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0.beta2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0.beta) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0.beta) lib/rack/runtime.rb:17:in `call'
activesupport (4.2.0.beta2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0.beta) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0.beta2) lib/action_dispatch/middleware/static.rb:103:in `call'
rack (1.6.0.beta) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0.beta2) lib/rails/engine.rb:514:in `call'
railties (4.2.0.beta2) lib/rails/application.rb:161:in `call'
rack (1.6.0.beta) lib/rack/tempfile_reaper.rb:15:in `call'
rack (1.6.0.beta) lib/rack/lint.rb:49:in `_call'
rack (1.6.0.beta) lib/rack/lint.rb:37:in `call'
rack (1.6.0.beta) lib/rack/showexceptions.rb:24:in `call'
rack (1.6.0.beta) lib/rack/commonlogger.rb:33:in `call'
rack (1.6.0.beta) lib/rack/chunked.rb:54:in `call'
rack (1.6.0.beta) lib/rack/content_length.rb:15:in `call'
rack (1.6.0.beta) lib/rack/handler/webrick.rb:89:in `service'
/Users/arezarazu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/arezarazu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/arezarazu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
答案 0 :(得分:9)
查看堆栈跟踪和您提供的代码,问题似乎是在has_attached_file
类中调用Artist
。
我怀疑这个问题是由回形针版本3.5.4和Rails 4.2之间的不兼容性引起的。我建议你升级回形针宝石。
在该gem的更改列表中,我看到列出的版本为4.1.1:
错误修复:回调链终结符在Rails 4.1中有所不同,删除 警告
这很可能是罪魁祸首。
答案 1 :(得分:1)
如果你正在运行Rails 4.0+,请确保将'paperclip'gem文件更改为'〜&gt; 4.2'如建议的那样。它将是:'paperclip','〜&gt; 4.2'