undefined method `follower' on .save() - ruby-on-rails

I'm new to rails and trying to learn the framework by creating an application. What I'm trying is to save a record to the database without using POST data. All the magic should be done after hitting a follow link.
My code:
def create
#user = User.find(session[:user_id])
#follower = Follower.new(followers: #user.username, following: params[:format])
if #follower.save
redirect_to #user, notice: "You are now following #{params[:format]}"
end
end
The Model:
class Follower < ActiveRecord::Base
validates :follower, presence: true
validates :following, presence: true
end
The error im getting:
NoMethodError in FollowersController#create
undefined method `follower' for #<Follower:0x007fe382c248c8>
Stack Trace:
activemodel (4.0.3) lib/active_model/attribute_methods.rb:439:in `method_missing'
activerecord (4.0.3) lib/active_record/attribute_methods.rb:155:in `method_missing'
activemodel (4.0.3) lib/active_model/validator.rb:151:in `block in validate'
activemodel (4.0.3) lib/active_model/validator.rb:150:in `each'
activemodel (4.0.3) lib/active_model/validator.rb:150:in `validate'
activerecord (4.0.3) lib/active_record/validations/presence.rb:5:in `validate'
activesupport (4.0.3) lib/active_support/callbacks.rb:283:in `_callback_before_447'
activesupport (4.0.3) lib/active_support/callbacks.rb:377:in `_run__290785027829406180__validate__callbacks'
activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
activemodel (4.0.3) lib/active_model/validations.rb:373:in `run_validations!'
activemodel (4.0.3) lib/active_model/validations/callbacks.rb:106:in `block in run_validations!'
activesupport (4.0.3) lib/active_support/callbacks.rb:373:in `_run__290785027829406180__validation__callbacks'
activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
activemodel (4.0.3) lib/active_model/validations/callbacks.rb:106:in `run_validations!'
activemodel (4.0.3) lib/active_model/validations.rb:314:in `valid?'
activerecord (4.0.3) lib/active_record/validations.rb:70:in `valid?'
activerecord (4.0.3) lib/active_record/validations.rb:77:in `perform_validations'
activerecord (4.0.3) lib/active_record/validations.rb:51:in `save'
activerecord (4.0.3) lib/active_record/attribute_methods/dirty.rb:32:in `save'
activerecord (4.0.3) lib/active_record/transactions.rb:270:in `block (2 levels) in save'
activerecord (4.0.3) lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
activerecord (4.0.3) lib/active_record/transactions.rb:209:in `transaction'
activerecord (4.0.3) lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
activerecord (4.0.3) lib/active_record/transactions.rb:270:in `block in save'
activerecord (4.0.3) lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
activerecord (4.0.3) lib/active_record/transactions.rb:269:in `save'
app/controllers/followers_controller.rb:8:in `create'
actionpack (4.0.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.3) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.3) lib/active_support/callbacks.rb:403:in `_run__3353578329054758817__process_action__callbacks'
activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.3) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.3) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.3) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.3) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.3) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.3) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.3) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.3) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.3) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.3) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.3) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:680: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.3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.3) 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.3) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.3) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.3) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.3) lib/active_support/callbacks.rb:373:in `_run__1226512649512727885__call__callbacks'
activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.3) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.3) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.3) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.3) 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.3) 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.3) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.3) lib/rails/engine.rb:511:in `call'
railties (4.0.3) 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/bim/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/bim/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/bim/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

Based on the stacktrace and error, it looks like you are accessing follower method somewhere in Model and it does not exist.
Check the specified validations in Follower model
It should look like
validates :followers,.... ## Plural followers
and NOT as
validates :follower,....

Related

Why does Simple_Form's association method throw the "wrong number of arguments (0 for 1)" exception?

The association method from simple_form is throwing an exception on the most basic use, and I cannot figure out why. I'd appreciate any help.
I have a has_and_belongs_to_many association between the Users and Projects models:
project.rb:
class Project < ActiveRecord::Base
has_and_belongs_to_many :users
belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
...
user.rb:
class User < ActiveRecord::Base
has_and_belongs_to_many :projects
has_many :projects_owned, :class_name => "Project", :foreign_key => "owner_id"
...
edit.html.erb:
<%= simple_form_for #project do |f| %>
<%= f.input :name, input_html: { size: 61 } %>
<%= f.input :description, as: :text, input_html: { cols: 60 } %>
<%= f.association(:users) %>
<%= f.submit "Save project", class: "btn btn-large btn-primary" %>
<% end %>
All models have corresponding tables, and the association works correclty in Rspec tests and the Rails console.
When I build the form, exactly as specified in the simple_form documentation, I get the following error:
<ArgumentError: wrong number of arguments (0 for 1)>
Stack trace:
ArgumentError - wrong number of arguments (0 for 1):
simple_form (3.0.1) lib/simple_form/inputs/collection_input.rb:87:in `collection_includes_basic_objects?'
simple_form (3.0.1) lib/simple_form/inputs/collection_input.rb:70:in `detect_common_display_methods'
simple_form (3.0.1) lib/simple_form/inputs/collection_input.rb:57:in `detect_collection_methods'
simple_form (3.0.1) lib/simple_form/inputs/collection_select_input.rb:5:in `input'
simple_form (3.0.1) lib/simple_form/wrappers/many.rb:29:in `block in render'
simple_form (3.0.1) lib/simple_form/wrappers/many.rb:27:in `render'
simple_form (3.0.1) lib/simple_form/wrappers/root.rb:15:in `render'
simple_form (3.0.1) lib/simple_form/form_builder.rb:120:in `input'
simple_form (3.0.1) lib/simple_form/form_builder.rb:212:in `association'
app/views/projects/edit.html.erb:12:in `block in _app_views_projects_edit_html_erb___630637963_32694600'
actionpack (4.0.4) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
actionpack (4.0.4) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
actionpack (4.0.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionpack (4.0.4) lib/action_view/helpers/form_helper.rb:435:in `form_for'
simple_form (3.0.1) lib/simple_form/action_view_extensions/form_helper.rb:22:in `block in simple_form_for'
simple_form (3.0.1) lib/simple_form/action_view_extensions/form_helper.rb:41:in `with_simple_form_field_error_proc'
simple_form (3.0.1) lib/simple_form/action_view_extensions/form_helper.rb:21:in `simple_form_for'
app/views/projects/edit.html.erb:9:in `_app_views_projects_edit_html_erb___630637963_32694600'
actionpack (4.0.4) lib/action_view/template.rb:143:in `block in render'
activesupport (4.0.4) lib/active_support/notifications.rb:161:in `instrument'
actionpack (4.0.4) lib/action_view/template.rb:141:in `render'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:49:in `block (2 levels) in render_template'
actionpack (4.0.4) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.4) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:48:in `block in render_template'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:56:in `render_with_layout'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
actionpack (4.0.4) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionpack (4.0.4) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionpack (4.0.4) lib/action_view/renderer/renderer.rb:23:in `render'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:127:in `_render_template'
actionpack (4.0.4) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:120:in `render_to_body'
actionpack (4.0.4) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
actionpack (4.0.4) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:97:in `render'
actionpack (4.0.4) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.0.4) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
activesupport (4.0.4) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.0.4) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.0.4) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.0.4) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.0.4) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.4) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.4) lib/active_support/callbacks.rb:413:in `_run__482912548__process_action__callbacks'
activesupport (4.0.4) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.4) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.4) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.0.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.4) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.4) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.4) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.4) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.4) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.4) lib/action_dispatch/routing/route_set.rb:674: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.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.4) 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.4) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.4) lib/active_record/migration.rb:373:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.4) lib/active_support/callbacks.rb:373:in `_run__957210712__call__callbacks'
activesupport (4.0.4) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.4) 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.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.4) 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.4) 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.4) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.4) lib/rails/engine.rb:511:in `call'
railties (4.0.4) 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'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
The problem has something to do with the collection for the form field.
See if this works:
<%= f.association :users, collection: User.all %>
I haven't tracked down why the collection is needed yet, but that seems to be the problem.

In a Rails 4 app with Railscasts' custom exception handler (#53), how do I force someone to a 404 within a controller action

I've see How to redirect to a 404 in Rails? and it's multiple duplicates, but I'm trying to do the following with http://railscasts.com/episodes/53-handling-exceptions-revised also in place:
class ThingsController < ApplicationController
def show
#thing = Thing.find(params[:id])
if #thing.user != current_user && #thing.is_private?
# What do I put here to fake a 404?
end
end
end
I tried render text: "Not found", status: 404 but that does exactly that, just renders the text instead of handling it through the errors controller. I also tried render status: 404, but that still shows the record using the show template (albeit with a 404 status in the web inspector).
I'm sure this is dead simple, but I can't figure it out...
UPDATE: here is the framework trace when trying to access a private Thing that does not belong to the current_user as requested by #vee. Although, I had to set this back to get the trace:
# /config/environments/development.rb
config.consider_all_requests_local = true
Does that mess up the trace from the custom error handling though?
actionpack (4.0.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.3) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.3) lib/active_support/callbacks.rb:423:in `_run__1598237009408833250__process_action__callbacks'
activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.3) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.3) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.3) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.3) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.3) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.3) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.3) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.3) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.3) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.3) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.3) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.3) lib/action_dispatch/routing/route_set.rb:680: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.3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.3) 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.3) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.3) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.3) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.3) lib/active_support/callbacks.rb:373:in `_run__3933250874076526029__call__callbacks'
activesupport (4.0.3) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.3) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.3) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.3) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.3) 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.3) 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.3) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.3) lib/rails/engine.rb:511:in `call'
railties (4.0.3) 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/robs/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/robs/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/robs/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
UPDATE 2: Answered in the OP comments.
What you have is an authorization issue
You could use this tutorial to fix: How to make this action throw a 404?:
class ThingsController < ApplicationController
def show
#thing = Thing.find(params[:id])
raise ActiveRecord::RecordNotFound if (#thing.user != current_user) && (#thing.is_private?)
end
end

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)

ForbiddenAttributesError for another controller Wicked gem

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

Resources