问题
When I try to create a listing in my app with an image this error is thrown:
undefined method `call' for "result == false":String.
The error occurred after I installed devise gem. But devise shouldn't have anything to do with creating a new listing?
The other parts of the app works fine, and I can create new listings without images.
Error message
NoMethodError in ArtistsController#create
undefined method `call' for "result == false":String
The method it points to is a callback method in ActiveSupport found here on row 164
https://sourcegraph.com/github.com/rails/rails@master/.rubygem/activesupport/.def/ActiveSupport/Callbacks/$methods/halted_callback_hook
Anyone got any ideas what the issue could be? I'm very new to this, so if you need more information from me or if I need to rephrase my question, just let me know.
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, the exception seem to be thrown for the create method in the controller
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
User class
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
Artist class (listing model)
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
The form helper
<%= 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 %>
Full trace
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'
回答1:
Looking at the stack trace and the code you have provided, the problem seems to be the invocation of has_attached_file
in the Artist
class.
I would suspect that the problem is caused by incompatibilities between version 3.5.4 of the paperclip gem and Rails 4.2. I would suggest you upgrade the paperclip gem.
In the list of changes for that gem, I see listed for version 4.1.1:
Bug Fix: Callback chain terminator is different in Rails 4.1, remove warnings
That could well be the culprit.
回答2:
If you're running Rails 4.0+ make sure to change the 'paperclip' gem file to '~> 4.2' as suggested. It would be: 'paperclip', '~>4.2'
来源:https://stackoverflow.com/questions/26852485/ruby-on-rails-error-undefined-method-call-for-result-falsestring-erro