ForbiddenAttributesError for another controller Wicked gem - ruby-on-rails

Totally stumped on this. I can not get past this
class AfterSignupController < Wicked::WizardController
before_filter :authenticate_user!
steps :complete_basic_profile, :complete_skills, :complete_address, :complete_avatar
def show
#person = current_user.person
render_wizard
end
def update
#person = current_user.person
#person.update(params[:person])
render_wizard #person
end
def after_signup_params
params.require(:person).permit(:first_name, :last_name, :headline, :description)
end
def person_params
params.require(:person).permit(:first_name, :last_name, :headline, :description)
end
end
The form is posting
"person"=>{"first_name"=>"Job", "last_name"=>"Seeker", "headline"=>"", "description"=>""}
Yet I cannot get past this error
Started PATCH "/after_signup/complete_basic_profile" for 127.0.0.1 at 2013-09-23 22:10:53 +0800
DEPRECATION WARNING: Using #scope without passing a callable object is deprecated. For example `scope :red, where(color: 'red')` should be changed to `scope :red, -> { where(color: 'red') }`. There are numerous gotchas in the former usage and it makes the implementation more complicated and buggy. (If you prefer, you can just define a class method named `self.red`.). (called from <class:User> at /home/user/workspace/testappapp/models/user.rb:36)
/home/user/.rvm/gems/ruby-2.0.0-p247/bundler/gems/twitter-bootstrap-rails-40ffd567ee6b/app/helpers/bootstrap_flash_helper.rb:2: warning: already initialized constant BootstrapFlashHelper::ALERT_TYPES
/home/user/.rvm/gems/ruby-2.0.0-p247/bundler/gems/twitter-bootstrap-rails-40ffd567ee6b/app/helpers/bootstrap_flash_helper.rb:2: warning: previous definition of ALERT_TYPES was here
Processing by AfterSignupController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8t8UNlC8kfbAj+RUtz1LzRywrvtoAEBD7elR2C88KfU=", "person"=>{"first_name"=>"Job", "last_name"=>"Seeker", "headline"=>"", "description"=>""}, "commit"=>"Continue", "id"=>"complete_basic_profile"}
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
Person Load (0.3ms) SELECT `people`.* FROM `people` WHERE `people`.`user_id` = 1 ORDER BY `people`.`id` ASC LIMIT 1
(0.2ms) BEGIN
(0.1ms) ROLLBACK
Completed 500 Internal Server Error in 153ms
ActiveModel::ForbiddenAttributesError - ActiveModel::ForbiddenAttributesError:
activemodel (4.0.0) lib/active_model/forbidden_attributes_protection.rb:21:in `sanitize_for_mass_assignment'
activerecord (4.0.0) lib/active_record/attribute_assignment.rb:21:in `assign_attributes'
activerecord (4.0.0) lib/active_record/persistence.rb:229:in `block in update'
activerecord (4.0.0) lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
activerecord (4.0.0) lib/active_record/transactions.rb:209:in `transaction'
activerecord (4.0.0) lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
activerecord (4.0.0) lib/active_record/persistence.rb:228:in `update'
app/controllers/after_signup_controller.rb:18:in `update'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:433:in `_run__108139916925402627__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655: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 `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
remotipart (1.2.1) lib/remotipart/middleware.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__245650492627359150__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (1.0.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.0.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.0.1) lib/better_errors/middleware.rb:56:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/user/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/user/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/user/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

def update
#person = current_user.person
#person.update(person_params)
render_wizard #person
end
Read about Strong Parameters

Related

Redirect fails in RailsAdmin config

I'm setting RailsAdmin to redirect to home page if user is not an admin. However, the redirecting fails. Here's the error message I got:
ActionController::UrlGenerationError in RailsAdmin::MainController#dashboard
No route matches {:controller=>"home", :action=>"index"} missing required keys: []
The code in rails_admin.rb is as follows. At the top the config file:
ADMIN_EMAILS= ['my#email.com']
Here's the rest of the code to restrict access to admin only:
config.authorize_with do
is_admin = ADMIN_EMAILS.include?(current_user.email)
if current_user
redirect_to root_path unless is_admin
end
end
This is the full stack trace:
actionpack (4.0.0) lib/action_dispatch/journey/formatter.rb:35:in `generate'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:576:in `generate'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:606:in `generate'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:642:in `url_for'
actionpack (4.0.0) lib/action_dispatch/routing/url_for.rb:155:in `url_for'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:209:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:178:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:249:in `block (2 levels) in define_url_helper'
config/initializers/rails_admin.rb:17:in `block (2 levels) in <top (required)>'
rails_admin (0.6.1) app/controllers/rails_admin/application_controller.rb:47:in `instance_eval'
rails_admin (0.6.1) app/controllers/rails_admin/application_controller.rb:47:in `_authorize!'
activesupport (4.0.0) lib/active_support/callbacks.rb:417:in `_run__951280075470168079__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/railtie/configurable.rb:30:in `method_missing'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
rack-pjax (0.7.0) lib/rack/pjax.rb:12:in `call'
omniauth (1.2.1) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.1) lib/omniauth/strategy.rb:164: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.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
remotipart (1.2.1) lib/remotipart/middleware.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__3119277781403351019__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/test/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/test/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/test/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
I hope you've gotten this figured out. I was just working through this one myself and found that I had to use this to get it working:
redirect_to main_app.root_path
Otherwise you're stuck with the routes within the RailsAdmin engine.

Surveyor gem NoMethodError

i'm stuck setting up a simple rails survey using the surveyor gem. I am following the basic instructions given here, on a new rails project: http://nubic.github.io/surveyor/
additionally, my gemfile includes the following in order to deal with rails 4 issues:
gem 'surveyor', :git => 'git://github.com/NUBIC/surveyor.git', :branch => 'rails4'
gem 'formtastic'
when i try to run the demo survey (kitchen sink), i end up with the following error:
NoMethodError in SurveyorController#edit
undefined method `with_sections_and_questions' for #<Class:0x007fe84d519450>
How to fix this?
SOLUTION: i have submitted a bugreport with the authors of surveyor. It seems that the gem is still awaiting an upgrade for rails 4. In the meantime, this development branch can be used to get things going:
gem 'surveyor', github: 'caboteria/surveyor', branch: 'rails4'
gem 'protected_attributes'
edit: full trace:
activerecord (4.0.0) lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/surveyor-70ed3f257416/lib/surveyor/surveyor_controller_methods.rb:63:in `edit'
app/controllers/surveyor_controller.rb:21:in `edit'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:443:in `_run__290069008777388403__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/railtie/configurable.rb:30:in `method_missing'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__3872098118566400954__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Request
Parameters:
{"survey_code"=>"kitchen-sink-survey",
"response_set_code"=>"tyr1KN5kAw"}
Edit 2: issued grep as asked
$ grep with_sections_and_questions $(bundle show surveyor) -r –
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/surveyor- 70ed3f257416/lib/surveyor/models/response_set_methods.rb: { :questions => survey.with_sections_and_questions.sections.map(&:questions).flatten.compact.size,
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/surveyor-70ed3f257416/lib/surveyor/models/response_set_methods.rb: qs = survey.with_sections_and_questions.sections.map(&:questions).flatten
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/surveyor-70ed3f257416/lib/surveyor/surveyor_controller_methods.rb: #survey = Survey.with_sections_and_questions.find_by_id(#response_set.survey_id)
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/surveyor-70ed3f257416/spec/models/survey_spec.rb: survey.with_sections_and_questions.sections.map(&:questions).flatten.should have(4).questions
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/surveyor-70ed3f257416/spec/models/survey_spec.rb: survey.with_sections_and_questions.sections.map(&:questions).flatten.should == [q4,q1,q3,q2]
grep: –: No such file or directory
edit 3: more info added:
$ grep with_sections_and_questions /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/ -r;
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems//surveyor-70ed3f257416/lib/surveyor/models/response_set_methods.rb: { :questions => survey.with_sections_and_questions.sections.map(&:questions).flatten.compact.size,
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems//surveyor-70ed3f257416/lib/surveyor/models/response_set_methods.rb: qs = survey.with_sections_and_questions.sections.map(&:questions).flatten
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems//surveyor-70ed3f257416/lib/surveyor/surveyor_controller_methods.rb: #survey = Survey.with_sections_and_questions.find_by_id(#response_set.survey_id)
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems//surveyor-70ed3f257416/spec/models/survey_spec.rb: survey.with_sections_and_questions.sections.map(&:questions).flatten.should have(4).questions
/usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems//surveyor-70ed3f257416/spec/models/survey_spec.rb: survey.with_sections_and_questions.sections.map(&:questions).flatten.should == [q4,q1,q3,q2]
The error:
undefined method `with_sections_and_questions' for #<Class:0x007fe84d519450>
says that the class Class has no instance method #with_sections_and_questions. You shall to search the method #with_sections_and_questions over all gems involved in your project. Try search as follows:
grep with_sections_and_questions /usr/local/rvm/gems/ruby-2.0.0-p247/bundler/gems/ -r
If grep don't find out the definitions of the method similar to:
def with_sections_and_questions
you have to open an issue on the problem to developers on their issue page.

Rails4 fails to save object with has_many-association

Problem solved! It seems that "ChangedAttribute" is not allowed as an association's name.
I'm having an application using Rails with ActiveLdap.
After updating a record in LDAP, I want to add a corresponding EmployeeChange-record in the database. The EmployeeChange-model has a has_many association to the ChangedAttribute-model.
def update
# write changes to LDAP
#employee = Employee.find(params[:id])
#employee.attributes = params[:employee].permit(:sn, :gn, :telephoneNumber, :physicalDeliveryOfficeName)
changes = #employee.changed_attributes
if #employee.save then
#when writing successful
employeeChange = EmployeeChange.new(:employee_cn => #employee.cn, :user_id => current_user.id)
employeeChange.save
end
respond_to do |format|
format.js
end
end
The EmployeeChange-Class
class EmployeeChange < ActiveRecord::Base
has_many :changed_attributes
#ActiveLdap-Connection
def employee
Employee.find(employee_cn)
end
end
The ChangedAttribute-Class
class ChangedAttribute < ActiveRecord::Base
belongs_to :employee_change
end
But when calling employeeChange.save, rails fails with this stacktrace:
Started PATCH "/employees/d1037" for 10.0.2.2 at 2014-01-05 14:35:38 +0100
Processing by EmployeesController#update as JS
Parameters: {"utf8"=>"✓", "employee"=>{"gn"=>"Hannes", "sn"=>"Linsen", "telephoneNumber"=>"T-1337", "physicalDeliveryOffice
Name"=>""}, "id"=>"d1037"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
LDAP: search_with_limit (0.5ms): {:base=>"ou=Benutzer,dc=foo,dc=bar", :scope=>:sub, :filter=>"(&(cn=d1037)(objectClass=per
son))", :attributes=>["*", "objectClass"], :limit=>1}
LDAP: modify (1.9ms): {:dn=>"cn=d1037,ou=Benutzer,dc=foo,dc=bar", :attributes=>[[:replace, "physicalDeliveryOfficeName", {
"physicalDeliveryOfficeName"=>[]}]]}
(0.1ms) begin transaction
(0.1ms) rollback transaction
Completed 500 Internal Server Error in 63ms
NoMethodError - undefined method `keys' for #<ActiveRecord::Associations::CollectionProxy []>:
activerecord (4.0.2) lib/active_record/relation/delegation.rb:121:in `method_missing'
activerecord (4.0.2) lib/active_record/relation/delegation.rb:68:in `method_missing'
activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/collection_proxy.rb:22:in `method_missing'
activemodel (4.0.2) lib/active_model/dirty.rb:112:in `changed'
activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:84:in `keys_for_partial_write'
activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:78:in `create_record'
activerecord (4.0.2) lib/active_record/callbacks.rb:306:in `block in create_record'
activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__4122661215117885092__create__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
activerecord (4.0.2) lib/active_record/callbacks.rb:306:in `create_record'
activerecord (4.0.2) lib/active_record/timestamp.rb:57:in `create_record'
activerecord (4.0.2) lib/active_record/persistence.rb:477:in `create_or_update'
activerecord (4.0.2) lib/active_record/callbacks.rb:302:in `block in create_or_update'
activesupport (4.0.2) lib/active_support/callbacks.rb:383:in `_run__4122661215117885092__save__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
activerecord (4.0.2) lib/active_record/callbacks.rb:302:in `create_or_update'
activerecord (4.0.2) lib/active_record/persistence.rb:106:in `save'
activerecord (4.0.2) lib/active_record/validations.rb:51:in `save'
activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:32:in `save'
activerecord (4.0.2) lib/active_record/transactions.rb:270:in `block (2 levels) in save'
activerecord (4.0.2) lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
activerecord (4.0.2) lib/active_record/transactions.rb:209:in `transaction'
activerecord (4.0.2) lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
activerecord (4.0.2) lib/active_record/transactions.rb:270:in `block in save'
activerecord (4.0.2) lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
activerecord (4.0.2) lib/active_record/transactions.rb:269:in `save'
app/controllers/employees_controller.rb:28:in `update'
actionpack (4.0.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.2) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.2) lib/active_support/callbacks.rb:423:in `_run__1739796840906245504__process_action__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
activeldap (4.0.1) lib/active_ldap/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.2) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.2) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:680: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 `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.2) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.2) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__4410864778172765141__call__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.2) lib/rails/engine.rb:511:in `call'
railties (4.0.2) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Any ideas what the problem might be?
Kind regards,
Tobias
Change
employeeChange = EmployeeChange.new(employee_cn = #employee.cn, user_id = current_user.id)
To
employeeChange = EmployeeChange.new(:employee_cn => #employee.cn, :user_id => current_user.id)

Active Admin and Rails 4

Update:
I think I finally solved it.. I had the following code in my Active Admin Initializer file:
module ActiveAdmin
class BaseController
with_role :admin
end
end
Removing this piece of code seems to fix the problem.
I'm setting up a new Rails 4 app, where I've just installed Active Admin on (gem 'activeadmin', github: 'gregbell/active_admin').
I can create new records from the rails console, but whenever I try to create a new record or update one within Active Admin I get the following error, which I can't seem to get my head around. Anyone who can point me in the right direction.
12:06:59 web.1 | Started GET "/admin/teams/new" for 127.0.0.1 at 2013-10-31 12:06:59 +0100
12:06:59 web.1 | Processing by Admin::TeamsController#new as HTML
12:06:59 web.1 | AdminUser Load (0.7ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 ORDER BY "admin_users"."id" ASC LIMIT 1
12:06:59 web.1 | Completed 500 Internal Server Error in 2ms
12:06:59 web.1 |
12:06:59 web.1 | ArgumentError (wrong number of arguments (2 for 0..1)):
and this is the stack trace:
activerecord (4.0.0) lib/active_record/core.rb:180: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'
/Users/KennethSkou/.rvm/gems/ruby-2.0.0-p247#Todo/bundler/gems/active_admin-0f663e3ad728/lib/active_admin/resource_controller/data_access.rb:142:in `build_new_resource'
/Users/KennethSkou/.rvm/gems/ruby-2.0.0-p247#Todo/bundler/gems/active_admin-0f663e3ad728/lib/active_admin/resource_controller/data_access.rb:129:in `build_resource'
inherited_resources (1.4.1) lib/inherited_resources/actions.rb:19:in `new'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:443:in `_run__3851194588154266790__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655: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.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__307601885218201832__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
thin (1.6.0) lib/thin/connection.rb:82:in `block in pre_process'
thin (1.6.0) lib/thin/connection.rb:80:in `catch'
thin (1.6.0) lib/thin/connection.rb:80:in `pre_process'
thin (1.6.0) lib/thin/connection.rb:55:in `process'
thin (1.6.0) lib/thin/connection.rb:41:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.6.0) lib/thin/backends/base.rb:73:in `start'
thin (1.6.0) lib/thin/server.rb:162:in `start'
rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.2) lib/rack/server.rb:264:in `start'
railties (4.0.0) lib/rails/commands/server.rb:84:in `start'
railties (4.0.0) lib/rails/commands.rb:78:in `block in <top (required)>'
railties (4.0.0) lib/rails/commands.rb:73:in `tap'
railties (4.0.0) lib/rails/commands.rb:73:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
My App/Admin/Team.rb file
ActiveAdmin.register Team do
def permitted_params
params.permit!
end
end

Using Paperclip on a video file in Rails 4 -- strong parameters issue?

I would like to add a video file to an Episode model using Paperclip in a Rails 4.0.0 app. However, I get an error "no implicit conversion of Symbol into Hash" when I call episode_params in my create action (second line):
def create
#episode = Episode.new(episode_params)
respond_to do |format|
if #episode.save
format.html { redirect_to #episode, notice: 'Episode was successfully created.' }
format.json { render action: 'show', status: :created, location: #episode }
else
format.html { render action: 'new' }
format.json { render json: #episode.errors, status: :unprocessable_entity }
end
end
end
My episode_params method:
def episode_params
params.require(:episode).permit(:name, :number, :description, :tag_list, :video => [:tempfile, :original_filename, :content_type, :headers])
end
And the params hash:
{"utf8"=>"✓", "authenticity_token"=>"VbOJvzWjlXMHOYpYMkwXUfdUxm9OcQx3LTMIJzk5eJQ=", "episode"=>{"name"=>"Test Episode 2", "number"=>"2", "description"=>"Testing Paperclip with video files", "tag_list"=>"test, file, video", "video"=>#<ActionDispatch::Http::UploadedFile:0x007fec361a80e0 #tempfile=#<Tempfile:/var/folders/yt/prn3v4gx3_bcrq8kr6wlfjjw0000gn/T/RackMultipart20130817-15917-1gu47ht>, #original_filename="file.mov", #content_type="video/quicktime", #headers="Content-Disposition: form-data; name=\"episode[video]\"; filename=\"file.mov\"\r\nContent-Type: video/quicktime\r\n">}, "commit"=>"Create Episode", "action"=>"create", "controller"=>"episodes"}
I've also tried with just :video instead of :video => [ etc ] with no luck. Any ideas would be greatly appreciated.
Full backtrace:
TypeError - no implicit conversion of Symbol into Hash:
paperclip (3.5.1) lib/paperclip/attachment.rb:72:in `initialize'
paperclip (3.5.1) lib/paperclip/has_attached_file.rb:46:in `block in define_instance_getter'
paperclip (3.5.1) lib/paperclip/has_attached_file.rb:65:in `block in define_setter'
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 `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'
app/controllers/episodes_controller.rb:34:in `create'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:413:in `_run__3623801457634608219__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655: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 `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__4451766820120855143__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/timhusson/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/timhusson/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/timhusson/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
As for your strong_params question, you should list only the name of the paperclip attachment. Assuming that your ARec class looks like this...
class Episode
has_attached_file :video, ... options ...
end
Then your params should look like this...
def episode_params
params.permit(:episode).permit(:name, :number, :description, :tag_list, :video)
end
You can actually get a sense of this if you look closely at the params hash. The :video item is a single object that has some attributes on it. Rails strong_params only cares that it's a single object and treats it like an integer or string so you only need to permit that attribute. I've got that type of thing working fine in a number of places.
Params are not your problem, however.
If you look at the backtrace, the error is coming from Paperclip::Attachment#initialize. Specifically, the referenced line (#72) says:
options = self.class.default_options.merge(options)
That makes a lot of sense in the context if you think about it. The error is telling you that you cannot covert a Symbol into a Hash. Most likely that means that the above statement is receiving a Symbol in the call to "merge(options)". Ultimately this probably means that your has_attached_file call in the class definition is improperly formatted.
Hrm, do you need "accepts_nested_attributes_for :video" in your episode model? Not sure if paperclip covers that or not. Also in your strong params you might try:
params.require(:episode).permit(:name, :number, :description, :tag_list, :video_attributes => [:tempfile, :original_filename, :content_type, :headers])
Ensure that your :default_url value is set to a valid path. I had the exact same problem and resolved it by setting a valid path.

Resources