I am developing a platform that allows merchants to upload a picture of their store. I am using Carrierwave+fog for this. As the app is hosted on heroku, the pictures will need to be stored on amazon s3.
On my local machine, everything works fine if the storage is local, but things go wrong once fog handles the uploading.
I will first post the local storage version (works fine), then my current fog-enabled s3 version together with the error that I am getting.
Local storage version (works fine):
# app/uploaders/picture_uploader.rb
class PictureUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
Fog-enabled s3 version (doesn't work):
# app/uploaders/picture_uploader.rb
class PictureUploader < CarrierWave::Uploader::Base
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
# config/initializers/fog.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'xxxx', # required
:aws_secret_access_key => 'xxxx' # required
}
config.fog_directory = 'yyyy' # required
config.fog_public = true # optional, defaults to true
end
When I now create or edit a new store, the picture is actually successfully uploaded to s3, but rails gives an Permission denied error message (app/tmp/carrierwave/20121104-0929-5512-8270/04.png could not be accessed).
Full Error Message:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/fileutils.rb:1406:in `unlink'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/fileutils.rb:1406:in `block in remove_file'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/fileutils.rb:1414:in `platform_support'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/fileutils.rb:1405:in `remove_file'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/fileutils.rb:785:in `remove_file'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/fileutils.rb:563:in `block in rm'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/fileutils.rb:562:in `each'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/fileutils.rb:562:in `rm'
carrierwave (0.5.8) lib/carrierwave/sanitized_file.rb:217:in `delete'
carrierwave (0.5.8) lib/carrierwave/uploader/store.rb:60:in `block in store!'
carrierwave (0.5.8) lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
carrierwave (0.5.8) lib/carrierwave/uploader/store.rb:58:in `store!'
carrierwave (0.5.8) lib/carrierwave/mount.rb:347:in `store!'
carrierwave (0.5.8) lib/carrierwave/mount.rb:217:in `store_bild!'
activesupport (3.1.0) lib/active_support/callbacks.rb:401:in `_run_save_callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
activerecord (3.1.0) lib/active_record/callbacks.rb:264:in `create_or_update'
activerecord (3.1.0) lib/active_record/persistence.rb:37:in `save'
activerecord (3.1.0) lib/active_record/validations.rb:50:in `save'
activerecord (3.1.0) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (3.1.0) lib/active_record/transactions.rb:241:in `block (2 levels) in save'
activerecord (3.1.0) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.1.0) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.1.0) lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
activerecord (3.1.0) lib/active_record/transactions.rb:241:in `block in save'
activerecord (3.1.0) lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
activerecord (3.1.0) lib/active_record/transactions.rb:240:in `save'
activerecord (3.1.0) lib/active_record/persistence.rb:163:in `block in update_attributes'
activerecord (3.1.0) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.1.0) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.1.0) lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
activerecord (3.1.0) lib/active_record/persistence.rb:161:in `update_attributes'
app/controllers/stores_controller.rb:62:in `block in update'
actionpack (3.1.0) lib/action_controller/metal/mime_responds.rb:269:in `call'
actionpack (3.1.0) lib/action_controller/metal/mime_responds.rb:269:in `retrieve_response_from_mimes'
actionpack (3.1.0) lib/action_controller/metal/mime_responds.rb:194:in `respond_to'
app/controllers/stores_controller.rb:61:in `update'
actionpack (3.1.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.1.0) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.1.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.1.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.1.0) lib/active_support/callbacks.rb:416:in `_run__16358980__process_action__192134115__callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.1.0) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.1.0) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.1.0) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.0) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.0) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.0) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.1.0) lib/action_controller/metal/params_wrapper.rb:201:in `process_action'
activerecord (3.1.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.1.0) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.1.0) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.1.0) lib/action_controller/metal.rb:193:in `dispatch'
actionpack (3.1.0) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.1.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:65:in `call'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:65:in `dispatch'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:29:in `call'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:75:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:531:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.6) lib/rack/etag.rb:23:in `call'
rack (1.3.6) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.6) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.6) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/cookies.rb:326:in `call'
activerecord (3.1.0) lib/active_record/query_cache.rb:62:in `call'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.0) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.6) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.0) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.6) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.6) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.6) lib/rack/lock.rb:15:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.0) lib/rails/engine.rb:455:in `call'
railties (3.1.0) lib/rails/rack/content_length.rb:16:in `call'
railties (3.1.0) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.6) lib/rack/handler/webrick.rb:59:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
This error confuses me, as typing in app/tmp/carrierwave/20121104-0929-5512-8270/04.png directly into the browser works fine.
For completeness sake, here is the controller & model (same in both versions)
#stores_controller.rb
def create
#store = Store.new(params[:store])
respond_to do |format|
if #store.save
format.html { redirect_to #store, notice: 'Store was successfully created.' }
format.json { render json: #store, status: :created, location: #store }
else
format.html { render action: "new" }
format.json { render json: #store.errors, status: :unprocessable_entity }
end
end
end
#models/store.rb
class Store < ActiveRecord::Base
mount_uploader :bild, PictureUploader
end
Try adding cache_dir to your uploader:
def cache_dir
"#{Rails.root}/tmp/uploads"
end
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
Also, you might have to add config/initializers/carrierwave.rb:
CarrierWave.configure do |config|
# hack fix for windows machine due to tmp file permission error
# per https://github.com/jnicklas/carrierwave/issues/220/
if ENV['RAILS_ENV'] != 'production'
config.delete_tmp_file_after_storage = false
end
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => ENV['MF_S3_KEY'], # required
:aws_secret_access_key => ENV['MF_S3_SECRET'], # required
:region => 'us-east-1' # optional, defaults to 'us-east-1'
}
config.fog_directory = ENV['MF_FLYER_BUCKET'] # required
#config.fog_host = 'https://assets.example.com' # optional, defaults to nil
#config.fog_public = false # optional, defaults to true
#config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
Related
I want to email users every time a new treatment that is under the category they are interested in is added.
I have a join table interests_users which is holds a user_id and a interest_id. Treatments has a variable called category which is used to compare against interests.
This is what the create block in my treatments controller looks like.
def create
#treatment = Treatment.new(treatment_params)
respond_to do |format|
if #treatment.save
interest = Interest.find_by(name: #treatment.category)
if interest
User.find_by_sql("SELECT * FROM users
INNER JOIN interests_users ON clients.id = interests_users.client_id
WHERE interests_users.interest_id = ?", interest.id).each do |user|
Bestevermailer.treatmentNotification(user, #treatment).deliver
end
end
format.html { redirect_to #treatment, notice: 'Treatment was successfully created.' }
format.json { render :show, status: :created, location: #treatment }
else
format.html { render :new }
format.json { render json: #treatment.errors, status: :unprocessable_entity }
end
end
end
Full Trace
activerecord (4.2.5) lib/active_record/connection_adapters/sqlite3_adapter.rb:289:in `exec_query'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/database_statements.rb:355:in `select'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `block in select_all'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/query_cache.rb:83:in `cache_sql'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `select_all'
activerecord (4.2.5) lib/active_record/querying.rb:39:in `find_by_sql'
app/controllers/treatments_controller.rb:72:in `block in create'
actionpack (4.2.5) lib/action_controller/metal/mime_responds.rb:212:in `respond_to'
app/controllers/treatments_controller.rb:68:in `create'
actionpack (4.2.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.5) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.5) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.5) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.5) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.5) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:76:in `call'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:817:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.5) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.5) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.5) lib/rails/engine.rb:518:in `call'
railties (4.2.5) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Try re-framing your query. Here:
User.joins('INNER JOIN interests_users ON clients.id = interests_users.client_id').where("interests_users.interest_id = ?", interest.id)
As per a similar SO:
find_by_sql doesn't work well with query placeholders
find_by_sql expects an array as a parameter:
User.find_by_sql([
"SELECT * FROM users
INNER JOIN interests_users
ON clients.id = interests_users.client_id
WHERE interests_users.interest_id = ?",
interest.id]).each do |user|
I'm following through Railscast #235 "Devise + OmniAuth Revised" and have run into a NoMethodError for Username whenever I try to authenticate using Twitter. I'm running Rails 3.2.
Specifically, it reads:
NoMethodError in OmniauthCallbacksController#twitter
undefined method `username' for #<User:0x007fa4744561c0>
app/models/user.rb:11:in `from_omniauth'
app/controllers/omniauth_callbacks_controller.rb:3:in `all'
I'm new to Rails, so any help would be much appreciated. Here's a look at my code:
The omniauth_callbacks_controller:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def all
user = User.from_omniauth(request.env["omniauth.auth"])
if user.persisted?
flash.notice = "Signed in!"
sign_in_and_redirect user
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
alias_method :twitter, :all
end
The user model:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :username
validates_presence_of :username
validates_uniqueness_of :username
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname
end
end
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
def password_required?
super && provider.blank?
end
def update_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
else
super
end
end
end
Framework Trace:
activemodel (3.2.8) lib/active_model/attribute_methods.rb:407:in `method_missing'
activerecord (3.2.8) lib/active_record/attribute_methods.rb:149:in `method_missing'
activemodel (3.2.8) lib/active_model/errors.rb:254:in `block in add_on_blank'
activemodel (3.2.8) lib/active_model/errors.rb:253:in `each'
activemodel (3.2.8) lib/active_model/errors.rb:253:in `add_on_blank'
activemodel (3.2.8) lib/active_model/validations/presence.rb:8:in `validate'
activesupport (3.2.8) lib/active_support/callbacks.rb:310:in `_callback_before_35'
activesupport (3.2.8) lib/active_support/callbacks.rb:473:in `_run__3967236747236009763__validate__2888041296400006394__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
activemodel (3.2.8) lib/active_model/validations.rb:227:in `run_validations!'
activemodel (3.2.8) lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
activesupport (3.2.8) lib/active_support/callbacks.rb:425:in `_run__3967236747236009763__validation__2888041296400006394__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
activemodel (3.2.8) lib/active_model/validations/callbacks.rb:53:in `run_validations!'
activemodel (3.2.8) lib/active_model/validations.rb:194:in `valid?'
activerecord (3.2.8) lib/active_record/validations.rb:69:in `valid?'
activerecord (3.2.8) lib/active_record/validations.rb:77:in `perform_validations'
activerecord (3.2.8) lib/active_record/validations.rb:50:in `save'
activerecord (3.2.8) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (3.2.8) lib/active_record/transactions.rb:241:in `block (2 levels) in save'
activerecord (3.2.8) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.2.8) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.2.8) lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
activerecord (3.2.8) lib/active_record/transactions.rb:241:in `block in save'
activerecord (3.2.8) lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
activerecord (3.2.8) lib/active_record/transactions.rb:240:in `save'
activerecord (3.2.8) lib/active_record/persistence.rb:45:in `create'
activerecord (3.2.8) lib/active_record/relation.rb:87:in `block in create'
activerecord (3.2.8) lib/active_record/relation.rb:241:in `block in scoping'
activerecord (3.2.8) lib/active_record/scoping.rb:98:in `with_scope'
activerecord (3.2.8) lib/active_record/relation.rb:241:in `scoping'
activerecord (3.2.8) lib/active_record/relation.rb:87:in `create'
activerecord (3.2.8) lib/active_record/relation.rb:119:in `first_or_create'
actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.8) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.8) lib/active_support/callbacks.rb:436:in `_run__3199821227742357635__process_action__2555454004410598156__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.8) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.8) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.8) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.8) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.8) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:36:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/mapper.rb:42:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:600:in `call'
omniauth (1.1.1) lib/omniauth/strategy.rb:394:in `call_app!'
omniauth (1.1.1) lib/omniauth/strategy.rb:356:in `callback_phase'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:58:in `callback_phase'
omniauth (1.1.1) lib/omniauth/strategy.rb:219:in `callback_call'
omniauth (1.1.1) lib/omniauth/strategy.rb:175:in `call!'
omniauth (1.1.1) lib/omniauth/strategy.rb:157:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/cookies.rb:339:in `call'
activerecord (3.2.8) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `_run__635784344197953786__call__2888041296400006394__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
thin (1.4.1) lib/thin/connection.rb:80:in `block in pre_process'
thin (1.4.1) lib/thin/connection.rb:78:in `catch'
thin (1.4.1) lib/thin/connection.rb:78:in `pre_process'
thin (1.4.1) lib/thin/connection.rb:53:in `process'
thin (1.4.1) lib/thin/connection.rb:38:in `receive_data'
eventmachine (1.0.0) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.0) lib/eventmachine.rb:187:in `run'
thin (1.4.1) lib/thin/backends/base.rb:63:in `start'
thin (1.4.1) lib/thin/server.rb:159:in `start'
rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
rack (1.4.1) lib/rack/server.rb:265:in `start'
railties (3.2.8) lib/rails/commands/server.rb:70:in `start'
railties (3.2.8) lib/rails/commands.rb:55:in `block in <top (required)>'
railties (3.2.8) lib/rails/commands.rb:50:in `tap'
railties (3.2.8) lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
You need to add a username column to your users table.
I can't seem to get CanCan working. This has turned out to be quite frustrating, especially when I have followed the rule book and tried, seemingly, all the tricks under the sun to get it to work.
I am using Rails 3.1.2, Devise 2.1.2, and CanCan 1.6.8. I set-up a separate role model as described by RyanB here.
This is my code.
1) ability.rb
class Ability
include CanCan::Ability
def initializer(user)
user ||= User.new # For users with no account
if (user.has_role?(:admin)) || (user.has_role?(:mod))
can :manage, :all
elsif user.has_role?(:registered)
can :read, :all
can :create, :all
can :update, Question do |question|
question.try(:user) == (user || user.has_role?(:admin) || user.has_role?(:mod))
end
can :destroy, Question do |question|
question.try(:user) == (user || user.has_role?(:admin) || user.has_role?(:mod))
end
else
can :read, :all
end
end
end
2) has_role? definition in user.rb
def has_role?(role_sym)
roles.any? { |r| r.name.underscore.to_sym == role_sym }
end
3) Controller before filters
before_filter :authenticate_user!, :except => :show
load_and_authorize_resource
skip_authorize_resource :only => :show
Authorizing any controller with CanCan results in the same error on all actions.
EDIT: Stack Trace
cancan (1.6.8) lib/cancan/controller_additions.rb:352:in `initialize'
cancan (1.6.8) lib/cancan/controller_additions.rb:352:in `new'
cancan (1.6.8) lib/cancan/controller_additions.rb:352:in `current_ability'
cancan (1.6.8) lib/cancan/controller_resource.rb:207:in `current_ability'
cancan (1.6.8) lib/cancan/controller_resource.rb:77:in `load_collection?'
cancan (1.6.8) lib/cancan/controller_resource.rb:33:in `load_resource'
cancan (1.6.8) lib/cancan/controller_resource.rb:25:in `load_and_authorize_resource'
cancan (1.6.8) lib/cancan/controller_resource.rb:10:in `block in add_before_filter'
activesupport (3.2.1) lib/active_support/callbacks.rb:429:in `_run__458654864__process_action__156152648__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__446710069__call__461654473__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/home/administrator/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/administrator/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/administrator/.rvm/rubies/ruby-1
.9.3-p125/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Okay, it seems, I did not followed ALL the rules of the rule book. Although I cannot see how this could be a problem. To get this working, I deleted my ability.rb file that I created manually, and used the rails g cancan:ability command to generate the same file in the same directory, and used the same code. And now it works like a charm.
I just can't seem to figure this one out...
As far as I know, you have to provide an instance variable to the form_for view helper, but it raises an error when I do that...
For a simple scaffold form_for I get an argument error wrong number of arguments (1 for 0) when supplying the instance of the model on a new action.
The relevan code:
Controller
class AdminMessagesController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource
def new
#admin_message = AdminMessage.new
logger.debug instance_variables
respond_to do |format|
format.html # new.html.erb
format.json { render json: #admin_message }
end
end
Controller instance_variables
[:#_routes, :#_action_has_layout, :#_view_context_class, :#_headers, :#_status, :#_request, :#_response, :#_env, :#_prefixes, :#_lookup_context, :#_action_name, :#_response_body, :#_config, :#_params, :#current_user, :#current_ability, :#admin_message, :#_authorized]
Model
class AdminMessage < ActiveRecord::Base
validates_presence_of :subject, :body
end
Roles (CanCan)
class Ability
include CanCan::Ability
def initialize(user)
# Define abilities for the passed in user here. For example:
user ||= User.new # guest user (not logged in)
if user.admin?
can :manage, :all
elsif user
can :manage, [Profile, BackgroundImage], :user_id => user.id
can :manage, Page, :profile => { :user_id => user.id }
can :read, [Profile]
else
can :read, [Profile]
end
New View
- #title = "New Message"
= link_to 'Back', admin_messages_path, class: 'button'
%hr
%h1= #title
= render 'form'
Form View
= form_for #admin_message do |f|
-if #admin_message.errors.any?
#error_explanation
%h2= "#{pluralize(#admin_message.errors.count, "error")} prohibited this admin_message from being saved:"
%ul
- #admin_message.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :subject
= f.text_field :subject
.field
= f.label :body
= f.text_area :body
.field
= f.label :send
= f.check_box :send
.actions
= f.submit 'Save'
Routes
resources :admin_messages
Stack Trace
ArgumentError in Admin_messages#new
Showing /example/app/views/admin_messages/_form.html.haml where line #4 raised:
wrong number of arguments (1 for 0)
Extracted source (around line #4):
1: -# - puts self.public_methods
2: -# - puts self.instance_variables
3:
4: = form_for #admin_message do |f|
5: -if #admin_message.errors.any?
6: #error_explanation
7: %h2= "#{pluralize(#admin_message.errors.count, "error")} prohibited this admin_message from being saved:"
Full Stack Trace
activerecord (3.1.2) lib/active_record/attribute_methods/read.rb:89:in `_send'
activerecord (3.1.2) lib/active_record/attribute_methods/primary_key.rb:8:in `to_key'
actionpack (3.1.2) lib/action_controller/record_identifier.rb:76:in `record_key_for_dom_id'
actionpack (3.1.2) lib/action_controller/record_identifier.rb:57:in `dom_id'
actionpack (3.1.2) lib/action_view/helpers/form_helper.rb:388:in `apply_form_for_options!'
actionpack (3.1.2) lib/action_view/helpers/form_helper.rb:365:in `form_for'
haml (3.1.3) lib/haml/helpers/action_view_mods.rb:182:in `form_for_with_haml'
haml (3.1.3) lib/haml/helpers/xss_mods.rb:132:in `form_for_with_haml_xss'
app/views/admin_messages/_form.html.haml:4:in `_app_views_admin_messages__form_html_haml__1654301332507974170_70145208768920'
actionpack (3.1.2) lib/action_view/template.rb:171:in `block in render'
activesupport (3.1.2) lib/active_support/notifications.rb:55:in `instrument'
actionpack (3.1.2) lib/action_view/template.rb:169:in `render'
actionpack (3.1.2) lib/action_view/renderer/partial_renderer.rb:256:in `render_partial'
actionpack (3.1.2) lib/action_view/renderer/partial_renderer.rb:228:in `block (2 levels) in render'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:33:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:33:in `instrument'
actionpack (3.1.2) lib/action_view/renderer/partial_renderer.rb:227:in `block in render'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:22:in `wrap_formats'
actionpack (3.1.2) lib/action_view/renderer/partial_renderer.rb:219:in `render'
actionpack (3.1.2) lib/action_view/renderer/renderer.rb:41:in `render_partial'
actionpack (3.1.2) lib/action_view/helpers/rendering_helper.rb:27:in `render'
haml (3.1.3) lib/haml/helpers/action_view_mods.rb:11:in `block in render_with_haml'
haml (3.1.3) lib/haml/helpers.rb:90:in `non_haml'
haml (3.1.3) lib/haml/helpers/action_view_mods.rb:11:in `render_with_haml'
app/views/admin_messages/new.html.haml:6:in `_app_views_admin_messages_new_html_haml__1382734216418550338_70145179834340'
actionpack (3.1.2) lib/action_view/template.rb:171:in `block in render'
activesupport (3.1.2) lib/active_support/notifications.rb:55:in `instrument'
actionpack (3.1.2) lib/action_view/template.rb:169:in `render'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:40:in `block (2 levels) in render_template'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:33:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:33:in `instrument'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:39:in `block in render_template'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:47:in `render_with_layout'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:38:in `render_template'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:12:in `block in render'
actionpack (3.1.2) lib/action_view/renderer/abstract_renderer.rb:22:in `wrap_formats'
actionpack (3.1.2) lib/action_view/renderer/template_renderer.rb:9:in `render'
actionpack (3.1.2) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.1.2) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.1.2) lib/abstract_controller/rendering.rb:120:in `_render_template'
actionpack (3.1.2) lib/action_controller/metal/streaming.rb:250:in `_render_template'
actionpack (3.1.2) lib/abstract_controller/rendering.rb:114:in `render_to_body'
actionpack (3.1.2) lib/action_controller/metal/renderers.rb:30:in `render_to_body'
actionpack (3.1.2) lib/action_controller/metal/compatibility.rb:43:in `render_to_body'
actionpack (3.1.2) lib/abstract_controller/rendering.rb:99:in `render'
actionpack (3.1.2) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.1.2) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/victorstan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
activesupport (3.1.2) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.1.2) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.1.2) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.1.2) lib/action_controller/metal/mime_responds.rb:268:in `block in retrieve_response_from_mimes'
actionpack (3.1.2) lib/action_controller/metal/mime_responds.rb:195:in `call'
actionpack (3.1.2) lib/action_controller/metal/mime_responds.rb:195:in `respond_to'
app/controllers/admin_messages_controller.rb:33:in `new'
actionpack (3.1.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.1.2) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.1.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.1.2) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.1.2) lib/active_support/callbacks.rb:434:in `_run__1801240210143518790__process_action__2938188811796736454__callbacks'
activesupport (3.1.2) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
activesupport (3.1.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.2) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.1.2) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.2) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.1.2) lib/action_controller/metal/params_wrapper.rb:201:in `process_action'
activerecord (3.1.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.1.2) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.1.2) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.1.2) lib/action_controller/metal.rb:193:in `dispatch'
actionpack (3.1.2) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.1.2) lib/action_controller/metal.rb:236:in `block in action'
actionpack (3.1.2) lib/action_dispatch/routing/route_set.rb:65:in `call'
actionpack (3.1.2) lib/action_dispatch/routing/route_set.rb:65:in `dispatch'
actionpack (3.1.2) lib/action_dispatch/routing/route_set.rb:29:in `call'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:82:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.2) lib/action_dispatch/routing/route_set.rb:532:in `call'
sass (3.1.10) lib/sass/plugin/rack.rb:54:in `call'
warden (1.1.0) lib/warden/manager.rb:35:in `block in call'
warden (1.1.0) lib/warden/manager.rb:34:in `catch'
warden (1.1.0) lib/warden/manager.rb:34:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.5) lib/rack/etag.rb:23:in `call'
rack (1.3.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/flash.rb:247:in `call'
rack (1.3.5) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.5) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/cookies.rb:331:in `call'
activerecord (3.1.2) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.1.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.2) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.2) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.5) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.2) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.5) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.2) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.5) lib/rack/lock.rb:15:in `call'
actionpack (3.1.2) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.2) lib/rails/engine.rb:456:in `call'
rack (1.3.5) lib/rack/content_length.rb:14:in `call'
railties (3.1.2) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.5) lib/rack/handler/webrick.rb:59:in `service'
/Users/victorstan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/victorstan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/victorstan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Update
If I try to inspect the #admin_message var in the controller #new action the error message changes to indicate and error in the controller instead of the view...
ArgumentError in AdminMessagesController#new
wrong number of arguments (1 for 0)
This happens if I add puts #admin_message.inspect to the controller action new
Moral of the story: Don't use send as a table column name!
I am calling the index action for a class which gives the following error:
Started GET "/images" for 127.0.0.1 at Sun Aug 28 06:14:41 +0200 2011
Processing by ImagesController#index as HTML Completed 500 Internal
Server Error in 1ms
ArgumentError (wrong number of arguments (2 for 0)):
There is nothing in the application trace, meaning that the failure occurs before any of the files that I created for app get processed. The full trace is here:
activesupport (3.0.8) lib/active_support/callbacks.rb:97:in `send'
activesupport (3.0.8) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (3.0.8) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.8) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.8) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.8) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.8) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.8) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.8) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.8) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.8) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.8) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.8) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.8) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:82:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.8) lib/action_dispatch/routing/route_set.rb:493:in `call'
sass (3.1.7) lib/sass/./sass/plugin/rack.rb:54:in `call'
warden (1.0.5) lib/warden/manager.rb:35:in `call'
warden (1.0.5) lib/warden/manager.rb:34:in `catch'
warden (1.0.5) lib/warden/manager.rb:34:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.3) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.8) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.8) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.8) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.8) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.8) lib/active_support/callbacks.rb:419:in `_run_call_callbacks'
actionpack (3.0.8) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.8) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
actionpack (3.0.8) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.8) lib/rails/application.rb:168:in `call'
railties (3.0.8) lib/rails/application.rb:77:in `send'
railties (3.0.8) lib/rails/application.rb:77:in `method_missing'
railties (3.0.8) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.3) lib/rack/content_length.rb:13:in `call'
rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:162:in `start'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:95:in `start'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:92:in `each'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:92:in `start'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:23:in `start'
/home/jon/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.3) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.3) lib/rack/server.rb:217:in `start'
railties (3.0.8) lib/rails/commands/server.rb:65:in `start'
railties (3.0.8) lib/rails/commands.rb:30
railties (3.0.8) lib/rails/commands.rb:27:in `tap'
railties (3.0.8) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
Here is the relevant code from lib/active_support/callbacks.rb, which I modified to print out the method arguments
def run_callbacks(kind, *args, &block)
p *args
p &block
p kind
send("_run_#{kind}_callbacks", *args, &block)
end
Here is the output with the above code:
"callback arguments"
:checkout
"callback arguments"
"index"
:process_action
Started GET "/images" for 127.0.0.1 at Sun Aug 28 06:40:37 +0200 2011
Processing by ImagesController#index as HTML Completed 500 Internal
Server Error in 1ms
ArgumentError (wrong number of arguments (2 for 0)):
Rendered
/home/jon/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb
(1.5ms) Rendered
/home/jon/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
(8.6ms) Rendered
/home/jon/.rvm/gems/ruby-1.8.7-p334/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
within rescues/layout (20.9ms)
Here is the DB schema:
create_table "images", :force => true do |t|
t.string "photo"
t.integer "w"
t.integer "h"
t.integer "eyes"
t.integer "head_top"
t.integer "head_bottom"
t.integer "user_id"
t.string "face_params", :limit => 2000
t.string "smiling"
t.string "facing"
t.string "filename"
t.string "content_type"
t.binary "data", :limit => 16777215
t.datetime "created_at"
t.datetime "updated_at"
end
Here is the relevant controller code:
def index
p "made it to index action--------------------------"
if user_signed_in?
#user = current_user
#selected_image = #user.get_selected_image
#problems = #selected_image ? #selected_image.problems.all : Array.new
#images = #user.images - Array[#selected_image]
#image = #user.image_build
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => #images }
end
else
redirect_to root_path
end
end
All the other controllers seem to work. Other actions for this controller give the same error.
Any ideas?
EDIT: Added Routes.rb as per comment below
Id::Application.routes.draw do
resources :payment_notifications
resources :addresses
resources :orders do
member do
get "select_address_for"
put "set_address_for"
get "complete"
end
end
resources :prints do
member do
post "email"
get "confirm_email"
end
end
resources :images do
member do
put "select"
get "thumb"
get "send"
end
end
resources :docs do
member do
get "image_for"
end
end
devise_for :users
##This will redirect the user after sign-in or sign-up.
##Otherwise is will default to the 'root' route, defined below
#devise_for :users do
# get 'users', :to => 'docs#index', :as => :user_root # Rails 3
#end
resources :admins
resources :assistants
resources :books
resources :links
resources :categories
resources :tips
resources :rules
resources :countries
resources :types
resources :continents
# match ':controller(/:action(/:id(.:format)))'
# match ':controller/:action/:id'
# match ':controller/:action/:id.:format'
# match ':controller/:action.:format'
end
You're redefining the send method in your images controller, which is a base ruby method. Rename it to something else and your problem should disappear.