I'm using Rails 5.1.6 with Puma and MySQL.
I have the below code in a Rails controller:
class ScansController < ApplicationController
before_action :find_device, only: %i[index new create]
.
.
.
def create
#scan = #device.scans.create(scan_params)
flash[:notice] = t('.success') if #scan.save
respond_with #scan.device, #scan
end
.
.
.
private
def find_device
#device = Device.find params[:device_id]
end
def scan_params
params.require(:scan).permit(:photo, :device_id, :reading, :reading_date)
end
end
And when I send a POST request to this URL the below happens:
Started POST "/en/devices/1/scans" for 81.0.89.20 at 2018-04-03 09:39:19 +0000
09:39:19 web.1 | Processing by ScansController#create as HTML
09:39:19 web.1 | Parameters: {"utf8"=>"✓", "authenticity_token"=>"QFdUs2thGPzJMbcWfApbattFMvnIEfzN1swrVGnbOTx7XbjY0Y3A8PLI1bRxqyBv6xIk9D2t13bfLPAqdSIyzQ==", "scan"=>{"reading_date"=>"2018-04-03T11:39:11", "reading"=>"6"}, "button"=>"", "locale"=>"en", "device_id"=>"1"}
09:39:19 web.1 | User Load (1.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
09:39:19 web.1 | Device Load (0.6ms) SELECT `devices`.* FROM `devices` WHERE `devices`.`id` = 1 LIMIT 1
09:39:19 web.1 | (0.6ms) BEGIN
09:39:19 web.1 | (0.7ms) ROLLBACK
09:39:19 web.1 | Completed 500 Internal Server Error in 33ms (ActiveRecord: 2.9ms)
09:39:19 web.1 |
09:39:19 web.1 |
09:39:19 web.1 |
09:39:19 web.1 | SystemStackError (stack level too deep):
09:39:19 web.1 |
09:39:19 web.1 | app/controllers/scans_controller.rb:35:in `create'
Now, line 35 is this line:#scan = #device.scans.create(scan_params)
and this was working well in Rails 4, but now that I migrated to Rails 5.1.6 it produces this behaviior even in my integration tests.
I hav no clue what could be the reason for this behavior. Does anyone sees something my eyes avoided for the last one or two weeks?
Thanx in advance.
The models:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
class Scan < ApplicationRecord
.
.
belongs_to :device, inverse_of: :scans
validates_attachment(
:photo,
content_type: {
content_type: [
'image/jpeg',
'image/gif',
'image/png',
'image/tiff'
]
}
)
with_options unless: #photo.present? do
validates :reading, presence: true
validates :reading, numericality: true
validates :reading_date, presence: true
end
.
end
class Device < ApplicationRecord
.
.
has_many :scans, inverse_of: :device, dependent: :restrict_with_error
validates :unit, presence: true
validates :name, presence: true
validates :serial, presence: true, uniqueness: true
validates :owner, presence: true
validates :precision, numericality: {
only_integer: true,
greater_than_or_equal_to: 0
}, allow_nil: true
.
.
end
The Full stack trace looks like this:
activesupport (5.1.6) lib/active_support/callbacks.rb:827:in `_run_validate_callbacks'
activemodel (5.1.6) lib/active_model/validations.rb:405:in `run_validations!'
activemodel (5.1.6) lib/active_model/validations/callbacks.rb:114:in `block in run_validations!'
activesupport (5.1.6) lib/active_support/callbacks.rb:131:in `run_callbacks'
activesupport (5.1.6) lib/active_support/callbacks.rb:827:in `_run_validation_callbacks'
activemodel (5.1.6) lib/active_model/validations/callbacks.rb:114:in `run_validations!'
activemodel (5.1.6) lib/active_model/validations.rb:335:in `valid?'
activerecord (5.1.6) lib/active_record/validations.rb:65:in `valid?'
activesupport (5.1.6) lib/active_support/callbacks.rb:422:in `block in inverted_lambda'
activesupport (5.1.6) lib/active_support/callbacks.rb:177:in `block (2 levels) in halting_and_conditional'
activesupport (5.1.6) lib/active_support/callbacks.rb:177:in `each'
activesupport (5.1.6) lib/active_support/callbacks.rb:177:in `all?'
activesupport (5.1.6) lib/active_support/callbacks.rb:177:in `block in halting_and_conditional'
activesupport (5.1.6) lib/active_support/callbacks.rb:507:in `block in invoke_before'
activesupport (5.1.6) lib/active_support/callbacks.rb:507:in `each'
activesupport (5.1.6) lib/active_support/callbacks.rb:507:in `invoke_before'
activesupport (5.1.6) lib/active_support/callbacks.rb:130:in `run_callbacks'
activesupport (5.1.6) lib/active_support/callbacks.rb:827:in `_run_validate_callbacks'
activemodel (5.1.6) lib/active_model/validations.rb:405:in `run_validations!'
activemodel (5.1.6) lib/active_model/validations/callbacks.rb:114:in `block in run_validations!'
activesupport (5.1.6) lib/active_support/callbacks.rb:131:in `run_callbacks'
activesupport (5.1.6) lib/active_support/callbacks.rb:827:in `_run_validation_callbacks'
activemodel (5.1.6) lib/active_model/validations/callbacks.rb:114:in `run_validations!'
activemodel (5.1.6) lib/active_model/validations.rb:335:in `valid?'
activerecord (5.1.6) lib/active_record/validations.rb:65:in `valid?'
activerecord (5.1.6) lib/active_record/validations.rb:82:in `perform_validations'
activerecord (5.1.6) lib/active_record/validations.rb:44:in `save'
activerecord (5.1.6) lib/active_record/attribute_methods/dirty.rb:35:in `save'
activerecord (5.1.6) lib/active_record/transactions.rb:308:in `block (2 levels) in save'
activerecord (5.1.6) lib/active_record/transactions.rb:384:in `block in with_transaction_returning_status'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/database_statements.rb:233:in `transaction'
activerecord (5.1.6) lib/active_record/transactions.rb:210:in `transaction'
activerecord (5.1.6) lib/active_record/transactions.rb:381:in `with_transaction_returning_status'
activerecord (5.1.6) lib/active_record/transactions.rb:308:in `block in save'
activerecord (5.1.6) lib/active_record/transactions.rb:323:in `rollback_active_record_state!'
activerecord (5.1.6) lib/active_record/transactions.rb:307:in `save'
activerecord (5.1.6) lib/active_record/suppressor.rb:42:in `save'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/active_record_prepend.rb:16:in `block in save'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/transaction.rb:917:in `with_database_metric_name'
newrelic_rpm (5.0.0.342) lib/new_relic/agent.rb:618:in `with_database_metric_name'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/active_record_prepend.rb:15:in `save'
activerecord (5.1.6) lib/active_record/associations/collection_association.rb:371:in `insert_record'
activerecord (5.1.6) lib/active_record/associations/has_many_association.rb:34:in `insert_record'
activerecord (5.1.6) lib/active_record/associations/collection_association.rb:360:in `block (2 levels) in _create_record'
activerecord (5.1.6) lib/active_record/associations/collection_association.rb:447:in `replace_on_target'
activerecord (5.1.6) lib/active_record/associations/collection_association.rb:281:in `add_to_target'
activerecord (5.1.6) lib/active_record/associations/collection_association.rb:358:in `block in _create_record'
activerecord (5.1.6) lib/active_record/associations/collection_association.rb:129:in `block in transaction'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
/usr/local/rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
activerecord (5.1.6) lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
activerecord (5.1.6) lib/active_record/transactions.rb:210:in `transaction'
activerecord (5.1.6) lib/active_record/associations/collection_association.rb:128:in `transaction'
activerecord (5.1.6) lib/active_record/associations/collection_association.rb:357:in `_create_record'
activerecord (5.1.6) lib/active_record/associations/has_many_association.rb:121:in `_create_record'
activerecord (5.1.6) lib/active_record/associations/association.rb:196:in `create'
activerecord (5.1.6) lib/active_record/associations/collection_proxy.rb:347:in `create'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.1.6) lib/active_support/callbacks.rb:108:in `block in run_callbacks'
activesupport (5.1.6) lib/active_support/core_ext/time/zones.rb:64:in `use_zone'
browser-timezone-rails (1.0.1) lib/browser-timezone-rails.rb:15:in `set_time_zone'
activesupport (5.1.6) lib/active_support/callbacks.rb:117:in `block in run_callbacks'
activesupport (5.1.6) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `instrument'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
activerecord (5.1.6) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.6) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.6) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.6) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/rack/browser_monitoring.rb:32:in `traced_call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.4) lib/rack/etag.rb:25:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.4) lib/rack/conditional_get.rb:38:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.4) lib/rack/head.rb:12:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.4) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.4) lib/rack/session/abstract/id.rb:226:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/cookies.rb:613:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
activerecord (5.1.6) lib/active_record/migration.rb:556:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.6) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rollbar (2.15.5) lib/rollbar/middleware/rails/rollbar.rb:24:in `block in call'
rollbar (2.15.5) lib/rollbar.rb:145:in `scoped'
rollbar (2.15.5) lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
rollbar (2.15.5) lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
railties (5.1.6) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
request_store (1.4.1) lib/request_store/middleware.rb:19:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.4) lib/rack/method_override.rb:22:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.4) lib/rack/runtime.rb:22:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack-rewrite (1.5.1) lib/rack/rewrite.rb:24:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/static.rb:125:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
railties (5.1.6) lib/rails/engine.rb:522:in `call'
newrelic_rpm (5.0.0.342) lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
puma (3.11.3) lib/puma/configuration.rb:225:in `call'
puma (3.11.3) lib/puma/server.rb:624:in `handle_request'
puma (3.11.3) lib/puma/server.rb:438:in `process_client'
puma (3.11.3) lib/puma/server.rb:302:in `block in run'
puma (3.11.3) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
This is the part which is repeating in the stack trace:
activesupport (5.1.6) lib/active_support/callbacks.rb:422:in 'block in inverted_lambda'
activesupport (5.1.6) lib/active_support/callbacks.rb:177:in 'block (2 levels) in halting_and_conditional'
activesupport (5.1.6) lib/active_support/callbacks.rb:177:in 'each'
activesupport (5.1.6) lib/active_support/callbacks.rb:177:in 'all?'
activesupport (5.1.6) lib/active_support/callbacks.rb:177:in 'block in halting_and_conditional'
activesupport (5.1.6) lib/active_support/callbacks.rb:507:in 'block in invoke_before'
activesupport (5.1.6) lib/active_support/callbacks.rb:507:in 'each'
activesupport (5.1.6) lib/active_support/callbacks.rb:507:in 'invoke_before'
activesupport (5.1.6) lib/active_support/callbacks.rb:130:in 'run_callbacks'
activesupport (5.1.6) lib/active_support/callbacks.rb:827:in '_run_validate_callbacks'
activemodel (5.1.6) lib/active_model/validations.rb:405:in 'run_validations!'
activemodel (5.1.6) lib/active_model/validations/callbacks.rb:114:in 'block in run_validations!'
activesupport (5.1.6) lib/active_support/callbacks.rb:131:in 'run_callbacks'
activesupport (5.1.6) lib/active_support/callbacks.rb:827:in '_run_validation_callbacks'
activemodel (5.1.6) lib/active_model/validations/callbacks.rb:114:in 'run_validations!'
activemodel (5.1.6) lib/active_model/validations.rb:335:in 'valid?'
activerecord (5.1.6) lib/active_record/validations.rb:65:in 'valid?'
It's a race condition.
I think you can only have 1 inverse_of since scan will call device and vice versa.
I've got the solution, although I don't exactly understand why it was working till now.
Originally there was the below validation in the Scan model (as I posted earlier):
with_options unless: #photo.present? do
validates :reading, presence: true
validates :reading, numericality: true
validates :reading_date, presence: true
end
In irb I managed to localize the error to this validation part. After refactoring the #photo.present? to a new method and calling that method in the validation, the problem is solved:
with_options unless: :has_photo? do
validates :reading, presence: true
validates :reading, numericality: true
validates :reading_date, presence: true
end
def has_photo?
#photo.present?
end
According to the document:
:unless option:
Specifies a method, proc or string to call to determine if
the validation should not occur. The method, proc
or string should return or evaluate to a true or false value.
But, your model Scan have unless: #photo.present?:
with_options unless: #photo.present? do
validates :reading, presence: true
...
end
That will lead to unexpected exceptions. In order to solve this issue, we should use any one of them below:
# Option 1:
with_options unless: proc { |scan| scan.photo.present? }
# Option 2:
with_options unless: 'photo.present?'
# Option 3:
with_options unless: :photo_present?
private
def photo_present?
photo.present?
end
In my case I encountered a similar error due to bad naming, please consider checking if the names could interfere with something inside of rails
Related
I've been following the Sorcery tutorial to build simple password authentication for a new (blank) Rails app. I've followed it very closely except for translating the erb to haml as I go along.
Everything has worked fine except that when testing the logout function it throws an error that seems to stump Google (see title).
The application trace shows only
app/controllers/user_sessions_controller.rb:16:in `destroy'
highlighting the logout line in user_sessions_controller.rb:
def destroy
logout
redirect_to(:users, notice: 'Logged out!')
end
I'll dump the framework trace below (it means very little to me) and am very happy to provide further information if you let me know what would be helpful. Generic advice on how to debug this kind of error would also be welcome.
activemodel (5.1.6) lib/active_model/attribute_methods.rb:432:in `method_missing'
sorcery (0.12.0) lib/sorcery/adapters/active_record_adapter.rb:6:in `block in update_attributes'
sorcery (0.12.0) lib/sorcery/adapters/active_record_adapter.rb:5:in `each'
sorcery (0.12.0) lib/sorcery/adapters/active_record_adapter.rb:5:in `update_attributes'
sorcery (0.12.0) lib/sorcery/model/submodules/remember_me.rb:67:in `force_forget_me!'
sorcery (0.12.0) lib/sorcery/model/submodules/remember_me.rb:61:in `forget_me!'
sorcery (0.12.0) lib/sorcery/controller/submodules/remember_me.rb:34:in `forget_me!'
sorcery (0.12.0) lib/sorcery/controller.rb:149:in `block in before_logout!'
sorcery (0.12.0) lib/sorcery/controller.rb:149:in `each'
sorcery (0.12.0) lib/sorcery/controller.rb:149:in `before_logout!'
sorcery (0.12.0) lib/sorcery/controller.rb:69:in `logout'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.1.6) lib/active_support/callbacks.rb:131:in `run_callbacks'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `instrument'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
activerecord (5.1.6) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.6) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.6) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.6) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in `call'
rack (2.0.5) lib/rack/etag.rb:25:in `call'
rack (2.0.5) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.5) lib/rack/head.rb:12:in `call'
rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.6) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.6) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.6.2) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.6.2) lib/web_console/middleware.rb:22:in `block in call'
web-console (3.6.2) lib/web_console/middleware.rb:20:in `catch'
web-console (3.6.2) lib/web_console/middleware.rb:20:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.6) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
railties (5.1.6) lib/rails/engine.rb:522:in `call'
puma (3.11.4) lib/puma/configuration.rb:225:in `call'
puma (3.11.4) lib/puma/server.rb:632:in `handle_request'
puma (3.11.4) lib/puma/server.rb:446:in `process_client'
puma (3.11.4) lib/puma/server.rb:306:in `block in run'
puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Restarting the Rails server resolved the problem.
I am using Devise auth token gem for authenticating some parts of my rails app. But when I try to log in, I get the following error:
POST http://localhost:3000/auth/sign_in 500 (Internal Server Error)
Here is the complete trace:
Started POST "/auth/sign_in" for 10.12.4.5 at 2018-05-30 09:29:36
+0500 Processing by DeviseTokenAuth::SessionsController#create as JSON Parameters: {"login"=>"admin", "password"=>"[FILTERED]",
"session"=>{"login"=>"admin", "password"=>"[FILTERED]"}} Completed 500
Internal Server Error in 14ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `each' for
):
devise_token_auth (0.1.43)
app/controllers/devise_token_auth/application_controller.rb:35:in
params_for_resource' devise_token_auth (0.1.43)
app/controllers/devise_token_auth/sessions_controller.rb:129:in
resource_params' devise_token_auth (0.1.43)
app/controllers/devise_token_auth/sessions_controller.rb:13:in
create' actionpack (5.1.6)
lib/action_controller/metal/basic_implicit_render.rb:4:in
send_action' actionpack (5.1.6)
lib/abstract_controller/base.rb:186:in process_action' actionpack
(5.1.6) lib/action_controller/metal/rendering.rb:30:in
process_action' actionpack (5.1.6)
lib/abstract_controller/callbacks.rb:20:in block in process_action'
activesupport (5.1.6) lib/active_support/callbacks.rb:131:in
run_callbacks' actionpack (5.1.6)
lib/abstract_controller/callbacks.rb:19:in process_action' actionpack
(5.1.6) lib/action_controller/metal/rescue.rb:20:inprocess_action'
actionpack (5.1.6)
lib/action_controller/metal/instrumentation.rb:32:in block in
process_action' activesupport (5.1.6)
lib/active_support/notifications.rb:166:inblock in instrument'
activesupport (5.1.6)
lib/active_support/notifications/instrumenter.rb:21:in instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in
instrument' actionpack (5.1.6)
lib/action_controller/metal/instrumentation.rb:30:in process_action'
actionpack (5.1.6)
lib/action_controller/metal/params_wrapper.rb:252:inprocess_action'
activerecord (5.1.6)
lib/active_record/railties/controller_runtime.rb:22:in
process_action' actionpack (5.1.6)
lib/abstract_controller/base.rb:124:inprocess' actionpack (5.1.6)
lib/action_controller/metal.rb:189:in dispatch' actionpack (5.1.6)
lib/action_controller/metal.rb:253:indispatch' actionpack (5.1.6)
lib/action_dispatch/routing/route_set.rb:49:in dispatch' actionpack
(5.1.6) lib/action_dispatch/routing/route_set.rb:31:inserve'
actionpack (5.1.6) lib/action_dispatch/routing/mapper.rb:16:in block
in <class:Constraints>' actionpack (5.1.6)
lib/action_dispatch/routing/mapper.rb:46:inserve' actionpack (5.1.6)
lib/action_dispatch/journey/router.rb:50:in block in serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:ineach'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in serve'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in
call' warden (1.2.7) lib/warden/manager.rb:36:in block in call'
warden (1.2.7) lib/warden/manager.rb:35:incatch' warden (1.2.7)
lib/warden/manager.rb:35:in call' rack (2.0.5) lib/rack/etag.rb:25:in
call' rack (2.0.5) lib/rack/conditional_get.rb:38:in call' rack
(2.0.5) lib/rack/head.rb:12:incall' activerecord (5.1.6)
lib/active_record/migration.rb:556:in call' actionpack (5.1.6)
lib/action_dispatch/middleware/callbacks.rb:26:inblock in call'
activesupport (5.1.6) lib/active_support/callbacks.rb:97:in
run_callbacks' actionpack (5.1.6)
lib/action_dispatch/middleware/callbacks.rb:24:incall' actionpack
(5.1.6) lib/action_dispatch/middleware/executor.rb:12:in call'
actionpack (5.1.6)
lib/action_dispatch/middleware/debug_exceptions.rb:59:incall'
actionpack (5.1.6)
lib/action_dispatch/middleware/show_exceptions.rb:31:in call'
railties (5.1.6) lib/rails/rack/logger.rb:36:incall_app' railties
(5.1.6) lib/rails/rack/logger.rb:24:in block in call' activesupport
(5.1.6) lib/active_support/tagged_logging.rb:69:inblock in tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in
tagged' activesupport (5.1.6)
lib/active_support/tagged_logging.rb:69:intagged' railties (5.1.6)
lib/rails/rack/logger.rb:24:in call' actionpack (5.1.6)
lib/action_dispatch/middleware/remote_ip.rb:79:incall' actionpack
(5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in call' rack
(2.0.5) lib/rack/runtime.rb:22:incall' activesupport (5.1.6)
lib/active_support/cache/strategy/local_cache_middleware.rb:27:in
call' actionpack (5.1.6)
lib/action_dispatch/middleware/executor.rb:12:incall' actionpack
(5.1.6) lib/action_dispatch/middleware/static.rb:125:in call' rack
(2.0.5) lib/rack/sendfile.rb:111:incall' rack-cors (1.0.2)
lib/rack/cors.rb:97:in call' railties (5.1.6)
lib/rails/engine.rb:522:incall' puma (3.11.4)
lib/puma/configuration.rb:225:in call' puma (3.11.4)
lib/puma/server.rb:632:inhandle_request' puma (3.11.4)
lib/puma/server.rb:446:in process_client' puma (3.11.4)
lib/puma/server.rb:306:inblock in run' puma (3.11.4)
lib/puma/thread_pool.rb:120:in `block in spawn_thread'
How can I fix the error?
application_controller.rb:
class ApplicationController < ActionController::API
include DeviseTokenAuth::Concerns::SetUserByToken
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:login, :first_name, :patronymic, :last_name, :email, :password, :password_confirmation) }
devise_parameter_sanitizer.permit(:sign_in) { |u| u.permit(:login, :password) }
devise_parameter_sanitizer.permit(:account_update) { |u| u.permit(:password, :password_confirmation, :current_password) }
end
end
user.rb:
class User < ActiveRecord::Base
self.table_name = 'DASHBOARD.V_L_USERS'
self.primary_key = 'user_id'
devise :database_authenticatable, :validatable, :authentication_keys => [:login]
include DeviseTokenAuth::Concerns::User
has_many :permission_references, as: :source
accepts_nested_attributes_for :permission_references, :allow_destroy => true
has_many :user_roles
has_many :spr_dashboards, foreign_key: 'l_users_id'
accepts_nested_attributes_for :user_roles, :allow_destroy => true
def email_required?
false
end
def password_required?
false
end
def is_participant
(read_attribute(:is_participant) == "Y")
end
def is_participant=(value)
write_attribute(:is_participant, (value == "1") ? "Y" : "N")
end
def children_users_ids
ActiveRecord::Base.connection.select_values <<-SQL.strip_heredoc
SELECT l_users_id_right
FROM DASHBOARD.V_L_USERS_RIGHTS
WHERE l_users_id = #{user_id}
SQL
end
end
routes.rb:
Rails.application.routes.draw do
mount_devise_token_auth_for 'User', at: 'auth'
end
It looks like blocks are not supported in devise_parameter_sanitizer. https://github.com/lynndylanhurley/devise_token_auth/issues/758#issuecomment-280797969
I'm creating a Rails Engine Classification, in which I have the Class Passion and a Concern Passionable.
I have also another engine Post, where I include the Passionable Concern. This Passionable Concern belongs to the Engine Classification in the /lib folder.
Turns out that, whenever I try to do a new Post passing the passion_ids, I get this error message:
NameError (uninitialized constant Feed::Post::Categorization):
"Categorization" is the jointable that I created in Engine
Classification.
The piece of code is posted down below.
Engine Classification
# passion.rb
module Classification
class Passion < ApplicationRecord
...
has_many :categorizations
has_many :posts, as: :categorizable, through: :categorizations
...
end
end
#==========================================//
# Classification.rb (JoinTable)
module Classification
class Categorization < ApplicationRecord
belongs_to :passion
belongs_to :categorizable, polymorphic: true
end
end
#===========================================//
# classification/lib/passionable.rb
require 'active_support/concern'
module Classification
module Passionable extend ActiveSupport::Concern
included do
has_many :categorizations, as: :categorizable
has_many :passions, through: :categorizations
end
end
end
Engine Post
module Feed
class Post < ApplicationRecord
has_many :pictures, class_name: "Feed::Picture"
include ::Classification::Passionable
...
end
end
Json to create post.
{
"post": {
"title": "My post title",
"content": "Lorem ipsum dolor sit amet..",
"passion_ids":["8bf8559a-857d-4ca5-82e1-f93dd3effc35","d51747b7-0960-460a-b15a-4b593155e2c5"]
}
}
ERROR MESSAGE:
NameError (uninitialized constant Feed::Post::Categorization):
activerecord (5.0.2) lib/active_record/inheritance.rb:152:in `compute_type'
activerecord (5.0.2) lib/active_record/reflection.rb:354:in `compute_class'
activerecord (5.0.2) lib/active_record/reflection.rb:350:in `klass'
activerecord (5.0.2) lib/active_record/reflection.rb:745:in `source_reflection'
activerecord (5.0.2) lib/active_record/reflection.rb:925:in `check_validity!'
activerecord (5.0.2) lib/active_record/associations/association.rb:25:in `initialize'
activerecord (5.0.2) lib/active_record/associations/has_many_through_association.rb:8:in `initialize'
activerecord (5.0.2) lib/active_record/associations.rb:240:in `new'
activerecord (5.0.2) lib/active_record/associations.rb:240:in `association'
activerecord (5.0.2) lib/active_record/associations/builder/collection_association.rb:66:in `passion_ids='
activemodel (5.0.2) lib/active_model/attribute_assignment.rb:46:in `public_send'
activemodel (5.0.2) lib/active_model/attribute_assignment.rb:46:in `_assign_attribute'
activemodel (5.0.2) lib/active_model/attribute_assignment.rb:40:in `block in _assign_attributes'
activemodel (5.0.2) lib/active_model/attribute_assignment.rb:39:in `each'
activemodel (5.0.2) lib/active_model/attribute_assignment.rb:39:in `_assign_attributes'
activerecord (5.0.2) lib/active_record/attribute_assignment.rb:26:in `_assign_attributes'
activemodel (5.0.2) lib/active_model/attribute_assignment.rb:33:in `assign_attributes'
activerecord (5.0.2) lib/active_record/core.rb:319:in `initialize'
activerecord (5.0.2) lib/active_record/inheritance.rb:65:in `new'
activerecord (5.0.2) lib/active_record/inheritance.rb:65:in `new'
engines/feed/app/controllers/feed/posts_controller.rb:21:in `create'
actionpack (5.0.2) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.0.2) lib/abstract_controller/base.rb:188:in `process_action'
actionpack (5.0.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.0.2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.0.2) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
activesupport (5.0.2) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.2) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.2) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.2) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.2) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.2) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.0.2) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.0.2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.2) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.0.2) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
activerecord (5.0.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.2) lib/abstract_controller/base.rb:126:in `process'
actionpack (5.0.2) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.2) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.2) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.2) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.2) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:725:in `call'
railties (5.0.2) lib/rails/engine.rb:522:in `call'
railties (5.0.2) lib/rails/railtie.rb:193:in `public_send'
railties (5.0.2) lib/rails/railtie.rb:193:in `method_missing'
actionpack (5.0.2) lib/action_dispatch/routing/mapper.rb:17:in `block in <class:Constraints>'
actionpack (5.0.2) lib/action_dispatch/routing/mapper.rb:46:in `serve'
actionpack (5.0.2) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.2) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.2) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:725:in `call'
rack (2.0.1) lib/rack/etag.rb:25:in `call'
rack (2.0.1) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.1) lib/rack/head.rb:12:in `call'
activerecord (5.0.2) lib/active_record/migration.rb:553:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.2) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.2) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.2) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.2) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.2) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.2) lib/rails/engine.rb:522:in `call'
puma (3.8.2) lib/puma/configuration.rb:224:in `call'
puma (3.8.2) lib/puma/server.rb:600:in `handle_request'
puma (3.8.2) lib/puma/server.rb:435:in `process_client'
puma (3.8.2) lib/puma/server.rb:299:in `block in run'
puma (3.8.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Your concern needs to provide a class_name option for the join table model:
# classification/lib/passionable.rb
require 'active_support/concern'
module Classification
module Passionable extend ActiveSupport::Concern
included do
has_many :categorizations, as: :categorizable, class_name: 'Classification::Categorization'
has_many :passions, through: :categorizations
end
end
end
Because your model and concern are under different namespaces.
I'm using the friendly_id gem to generate slugs.
I have a model like this
class Veterinarian < ApplicationRecord
extend FriendlyId
belongs_to :user
has_one :profile, through: :user
friendly_id :slug_string, use: :slugged
def slug_string
"#{profile.first_name} #{profile.last_name} #{profile.city}"
end
end
And another model like this.
class Profile < ApplicationRecord
include ReadOnlyModel
belongs_to :user
end
ReadOnlyModel looks like this
module ReadOnlyModel
extend ActiveSupport::Concern
included do
attr_readonly(*column_names)
end
def readonly?
true
end
def destroy
raise ActiveRecord::ReadOnlyRecord
end
def delete
raise ActiveRecord::ReadOnlyRecord
end
end
My issue comes when I'm trying to access profile attributes inside of the veterinarian model. profile.first_name, profile.last_name, etc.
When friendly_id tries to update the slug, it throws an error telling me that the profile model is read only, however I'm just accessing an attribute and using it to create a string for friendly_id to use, nothing is changing in the profile model. However I can do Veterinarian.last.slug_string in the console and it outputs correctly with no errors.
I'm testing this by doing Veterinarian.update(slug: nil) to set the slug to nil and trigger friendly_id to update it with the proper slug.
I've been scratching my head for a good hour and haven't been able to figure out what's going on. It's probably something simple that I'm overlooking. Any help would be appreciated.
my above models are wrapped in a Veterinarians module, I removed it in the code examples for readability reasons.
activerecord (5.0.0.beta3) lib/active_record/persistence.rb:533:in `create_or_update'
activerecord (5.0.0.beta3) lib/active_record/callbacks.rb:298:in `block in create_or_update'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:750:in `_run_save_callbacks'
activerecord (5.0.0.beta3) lib/active_record/callbacks.rb:298:in `create_or_update'
activerecord (5.0.0.beta3) lib/active_record/suppressor.rb:41:in `create_or_update'
activerecord (5.0.0.beta3) lib/active_record/persistence.rb:125:in `save'
activerecord (5.0.0.beta3) lib/active_record/validations.rb:44:in `save'
activerecord (5.0.0.beta3) lib/active_record/attribute_methods/dirty.rb:22:in `save'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:319:in `block (2 levels) in save'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
activerecord (5.0.0.beta3) lib/active_record/connection_adapters/abstract/database_statements.rb:228:in `transaction'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:211:in `transaction'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:319:in `block in save'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:334:in `rollback_active_record_state!'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:318:in `save'
activerecord (5.0.0.beta3) lib/active_record/persistence.rb:266:in `block in update'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
activerecord (5.0.0.beta3) lib/active_record/connection_adapters/abstract/database_statements.rb:230:in `block in transaction'
activerecord (5.0.0.beta3) lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
activerecord (5.0.0.beta3) lib/active_record/connection_adapters/abstract/database_statements.rb:230:in `transaction'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:211:in `transaction'
activerecord (5.0.0.beta3) lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
activerecord (5.0.0.beta3) lib/active_record/persistence.rb:264:in `update'
engines/practices/app/controllers/practices/clinic_veterinarians_controller.rb:13:in `show'
actionpack (5.0.0.beta3) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.0.0.beta3) lib/abstract_controller/base.rb:183:in `process_action'
actionpack (5.0.0.beta3) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.0.0.beta3) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:126:in `call'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:455:in `call'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0.beta3) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.0.beta3) lib/action_controller/metal/rescue.rb:27:in `process_action'
actionpack (5.0.0.beta3) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (5.0.0.beta3) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.0.beta3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.0.beta3) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.0.beta3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (5.0.0.beta3) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
activerecord (5.0.0.beta3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.0.beta3) lib/abstract_controller/base.rb:128:in `process'
actionview (5.0.0.beta3) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.0.beta3) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.0.beta3) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.0.beta3) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.0.beta3) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.0.beta3) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.0.beta3) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.0.beta3) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.0.beta3) lib/action_dispatch/routing/route_set.rb:724:in `call'
railties (5.0.0.beta3) lib/rails/engine.rb:522:in `call'
railties (5.0.0.beta3) lib/rails/railtie.rb:194:in `public_send'
railties (5.0.0.beta3) lib/rails/railtie.rb:194:in `method_missing'
actionpack (5.0.0.beta3) lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
actionpack (5.0.0.beta3) lib/action_dispatch/routing/mapper.rb:47:in `serve'
actionpack (5.0.0.beta3) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.0.beta3) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.0.beta3) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.0.beta3) lib/action_dispatch/routing/route_set.rb:724:in `call'
omniauth (1.3.0) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.3.0) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.3.0) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.3.0) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.3.0) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.3.0) lib/omniauth/strategy.rb:164:in `call'
actionview (5.0.0.beta3) lib/action_view/digestor.rb:12:in `call'
/Users/mike/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/remotipart-aa0386690bd2/lib/remotipart/middleware.rb:27:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `catch'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
/Users/mike/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rack-1aded61cedb0/lib/rack/etag.rb:25:in `call'
/Users/mike/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rack-1aded61cedb0/lib/rack/conditional_get.rb:25:in `call'
/Users/mike/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rack-1aded61cedb0/lib/rack/head.rb:12:in `call'
/Users/mike/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rack-1aded61cedb0/lib/rack/session/abstract/id.rb:222:in `context'
/Users/mike/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rack-1aded61cedb0/lib/rack/session/abstract/id.rb:216:in `call'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.0.0.beta3) lib/active_record/query_cache.rb:36:in `call'
activerecord (5.0.0.beta3) lib/active_record/connection_adapters/abstract/connection_pool.rb:963:in `call'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.0.beta3) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/reloader.rb:71:in `call'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.0.beta3) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.0.beta3) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.0.beta3) lib/active_support/tagged_logging.rb:70:in `block in tagged'
activesupport (5.0.0.beta3) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.0.beta3) lib/active_support/tagged_logging.rb:70:in `tagged'
railties (5.0.0.beta3) lib/rails/rack/logger.rb:24:in `call'
request_store (1.3.1) lib/request_store/middleware.rb:9:in `call'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/request_id.rb:24:in `call'
/Users/mike/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rack-1aded61cedb0/lib/rack/method_override.rb:22:in `call'
/Users/mike/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rack-1aded61cedb0/lib/rack/runtime.rb:22:in `call'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/load_interlock.rb:13:in `call'
actionpack (5.0.0.beta3) lib/action_dispatch/middleware/static.rb:136:in `call'
/Users/mike/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rack-1aded61cedb0/lib/rack/sendfile.rb:111:in `call'
railties (5.0.0.beta3) lib/rails/engine.rb:522:in `call'
puma (2.16.0) lib/puma/server.rb:557:in `handle_request'
puma (2.16.0) lib/puma/server.rb:404:in `process_client'
puma (2.16.0) lib/puma/server.rb:270:in `block in run'
puma (2.16.0) lib/puma/thread_pool.rb:106:in `block in spawn_thread'
After further digging, it appears that doing user.profile.attribute_name does not trigger the readonly error.
So I am using the latest active_model_serializer and I am trying to use them to send an array on Medium.
I use this to make a query for the Medium: Medium.includes([{comments: :user}, :user]).where(user_id: user_ids)
So the Medium belong to a user, medium has many comments and every comment has a user (owner).
Now here are the corresponding serializers:
Medium:
class MediumSerializer < ActiveModel::Serializer
attributes :id,
:text,
:image_video_file_name,
:image_video_croppable_url,
:image_video_thumb_url,
:image_video_big_url
belongs_to :user
has_many :comments
end
Comment:
class CommentSerializer < ActiveModel::Serializer
attributes :id,
:text,
:user_id,
:medium_id
belongs_to :user
end
User:
class UserSerializer < ActiveModel::Serializer
include Avatar
attributes :id,
:name,
:email,
:role,
:avatar
def avatar
Medium.find(self.current_avatar)[0]
end
#has_one :avatar, serializer: AvatarSerializer
has_many :media, :comments
end
And also I have these functions in my Medium:
def image_video_croppable_url
image_video.url(:croppable)
end
def image_video_thumb_url
image_video.url(:thumb)
end
def image_video_big_url
image_video.url(:big)
end
I use Paperclip gem and I needed these functions to get access to sizes of different medium images. Maybe there is a better way for it also.
So now when I do the query, I use this line to pass the info to browser and let the serializer make it JSON nicely:
respond_with media, each_serializer: MediumSerializer
But it gives me this error:
NoMethodError - undefined method `image_video_file_name' for #<Comment:0x007f5a082a4310>:
activemodel (4.2.0) lib/active_model/attribute_methods.rb:433:in `method_missing'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:37:in `block (2 levels) in attributes'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:200:in `block in attributes'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:198:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:198:in `each_with_object'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:198:in `attributes'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:22:in `block (3 levels) in serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter.rb:53:in `cache_check'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:21:in `block (2 levels) in serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/array_serializer.rb:5:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/array_serializer.rb:5:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:20:in `map'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:20:in `block in serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:224:in `call'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:224:in `block in each_association'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:208:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:208:in `each_association'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:17:in `serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:9:in `block in serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/array_serializer.rb:5:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/array_serializer.rb:5:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:9:in `map'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:9:in `serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter.rb:23:in `as_json'
activesupport (4.2.0) lib/active_support/json/encoding.rb:34:in `encode'
activesupport (4.2.0) lib/active_support/json/encoding.rb:21:in `encode'
activesupport (4.2.0) lib/active_support/core_ext/object/json.rb:37:in `to_json_with_active_support_encoder'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:116:in `block in <module:Renderers>'
active_model_serializers (0.10.0.rc1) lib/action_controller/serialization.rb:49:in `block (2 levels) in <module:Serialization>'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:45:in `block in _render_to_body_with_renderer'
/home/kaspar/.rbenv/versions/2.2.0/lib/ruby/2.2.0/set.rb:283:in `each_key'
/home/kaspar/.rbenv/versions/2.2.0/lib/ruby/2.2.0/set.rb:283:in `each'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:41:in `_render_to_body_with_renderer'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.0) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/kaspar/.rbenv/versions/2.2.0/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:40:in `render'
responders (2.1.0) lib/action_controller/responder.rb:258:in `display'
responders (2.1.0) lib/action_controller/responder.rb:212:in `api_behavior'
responders (2.1.0) lib/action_controller/responder.rb:191:in `rescue in to_format'
responders (2.1.0) lib/action_controller/responder.rb:185:in `to_format'
responders (2.1.0) lib/action_controller/responder.rb:163:in `respond'
responders (2.1.0) lib/action_controller/responder.rb:156:in `call'
responders (2.1.0) lib/action_controller/respond_with.rb:203:in `respond_with'
app/controllers/users_controller.rb:73:in `feed'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.1) lib/rack/etag.rb:24:in `call'
rack (1.6.1) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.1) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.1) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.1) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.1) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
passenger (5.0.7) lib/phusion_passenger/rack/thread_handler_extension.rb:89:in `process_request'
passenger (5.0.7) lib/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request'
passenger (5.0.7) lib/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
passenger (5.0.7) lib/phusion_passenger/request_handler.rb:414:in `block (3 levels) in start_threads'
passenger (5.0.7) lib/phusion_passenger/utils.rb:111:in `block in create_thread_and_abort_on_exception'
This error only occurs when I attempt to throw an array of Medium to the Serializer. With only one Medium I get no errors and the result is this:
As you can see it has all the attributes I wanted it to have in the serializer and it managed to fetch the info into all the attributes with no problems.
Why does this problem occur only when I do the same thing with an array or same objects?