I'm having some trouble with nested attributes when the defined classes are inside a module:
# file bar.rb
module Abc
class Bar << ActiveRecord::Base
has_many :foos
accepts_nested_attributes_for :foos
end
end
# file foo.rb
module Abc
class Foo << ActiveRecord::Base
belongs_to :bar
# let's consider an attribute: qux
end
end
# inside the controller
def new
#bar = Abc::Bar.new
end
# inside a view
<%= form_for #bar .... do |f| %>
....
<%= f.fields_for :abc_foos, #bar.foos do |ff| %>
<%= ff.hidden_field :qux, value: true %>
<% end %>
<% end %>
Now we got the prefix "abc" in the names attributes>
# the rendered html
<input type="hidden" name="abc_bar[abc_foos][qux]" ... />
The params now comes with the abc_foos included:
# the params hash
"abc_bar" => {
....
"abc_foos" => {"qux" => "some value"}
}
The problem: the accepts_nested_attributes_for method creates something like "abc_foos_attributes=" in order to receive the attributes, but the default param key name is different. So, this will not work:
# in the controller, again
def create
#bar = Abc::Bar.new(params.require(:abc_bar).permit(:a, :b, abc_foos: [:qux]))
end
I get the error:
unknown attribute 'abc_foos' for Abc::Bar.
I would expect something like "foos_attributes" as the appropriate key. What am I missing?
Thanks!
The full bactrace:
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:53:in `_assign_attribute'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:31:in `block in assign_nested_parameter_attributes'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:31:in `each'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:31:in `assign_nested_parameter_attributes'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:25:in `_assign_attributes'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:35:in `assign_attributes'
activerecord (5.2.1) lib/active_record/core.rb:314:in `initialize'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:in `new'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:in `new'
app/controllers/bar_controller.rb:33:in `create'
actionpack (5.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.1) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.1) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.1) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.1) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:840:in `call'
rack (2.0.6) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.6) lib/rack/etag.rb:25:in `call'
rack (2.0.6) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.6) lib/rack/head.rb:12:in `call'
actionpack (5.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.6) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.6) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.1) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.1) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:22:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.6) lib/rack/method_override.rb:22:in `call'
rack (2.0.6) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.6) lib/rack/sendfile.rb:111:in `call'
railties (5.2.1) lib/rails/engine.rb:524:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
Can you post full backtrace errors? But in the meantime if you try
<%= f.fields_for :foos, #bar.foos do |foo| %>
<%= foo.hidden_field :qux, value: true %>
<% end %>
you probably also need to do
#bar = Abc::Bar.new(params.require(:abc_bar).permit(:a, :b, foos: [:qux]))
Related
I am trying to call a method from a gem that I have created but keep getting the error stated in the title. I've looked into the error but still dont know why it is occurring. When I run the file in the Command prompt it works perfectly. All I want to do it populate the method with user input and display the result in my index page. I am running the following it the command prompt:
irb -rubygems
require 'unit_converter'
UnitConverter::Weight.new.conversions(1, :kg)
The output changes depending on what I type in but for example the output for this would be:
["2.20462pounds", "0.157473stone"]
It's only when I try and link it up to my erb file that i get the error mentioned.
To reproduce the error This is the method I am creating in my measurements_controller file:
def unit_converter
#input1 = params[:value]
#input2 = params[:unit]
#result = UnitConverter::Weight.new.conversions(#input1.to_i , #input2)
end
And in my index.html.erb file I have a form like so:
<%= form_tag "/validate" do %>
<%= text_field_tag :value %>
<%= text_field_tag :unit %>
<%= submit_tag "Search" %>
<% end %>
<%= #result %>
And these are my routes to link everything up
get '/check', :controller=>'measurements', :action=>'index'
post '/validate', :controller=>'measurements', :action=>'unit_converter'
This is the gem that I am using and conversions is the method:
module UnitConverter
class ConversionError < StandardError
end
class Weight
# lookup table
CONVERSIONS = {
kg: {
pounds: 2.20462,
stone: 0.157473,
},
pounds: {
kg: 0.453592,
stone: 0.0714286
},
stone: {
kg: 6.35029,
pounds: 14
}
}
def convert(value, from, to:)
raise ConversionError, "Value is not numeric" unless value.is_a? Numeric
raise ConversionError, "Value #{value} is not positive" unless value >= 0
"#{value * conversion_ratio(from, to) }#{to.to_s}"
end
def conversions(value, unit)
CONVERSIONS[unit].keys.map do |other_unit|
convert(value, unit, to: other_unit)
end
end
private
def conversion_ratio(from, to)
begin
CONVERSIONS.fetch(from).fetch(to)
rescue KeyError
raise ConversionError, "Cannot convert #{from.to_s} to #{to.to_s}"
end
end
end
end
My full stack trace:
**unit_converter (0.0.0) lib/unit_converter.rb:32:in `conversions'
app/controllers/measurements_controller.rb:9:in `unit_converter'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:196:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.2.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.2.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.2.1) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (6.0.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:51:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:837:in `call'
rack-pjax (1.1.0) lib/rack/pjax.rb:12:in `call'
remotipart (1.4.4) lib/remotipart/middleware.rb:32:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.2.2) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.2) lib/rack/etag.rb:27:in `call'
rack (2.2.2) lib/rack/conditional_get.rb:40:in `call'
rack (2.2.2) lib/rack/head.rb:12:in `call'
actionpack (6.0.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.2) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.2) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.2.1) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web-console (4.0.1) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.2) lib/rack/method_override.rb:24:in `call'
rack (2.2.2) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.2) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
webpacker (4.2.2) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.2.1) lib/rails/engine.rb:526:in `call'
puma (4.3.1) lib/puma/configuration.rb:228:in `call'
puma (4.3.1) lib/puma/server.rb:681:in `handle_request'
puma (4.3.1) lib/puma/server.rb:472:in `process_client'
puma (4.3.1) lib/puma/server.rb:328:in `block in run'
puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'**
When you are calling the conversions method from the console, you are passing in a symbol :kg ... but when the method is being called in the controller, it's receiving a String.
So you just need to convert the unit of measure to a symbol, the same way you are converting the number value to an integer:
#result = UnitConverter::Weight.new.conversions(#input1.to_i , #input2.to_sym)
The error you got was b/c the lookup in your conversions table was essentially looking for Conversions['kg'] which returns nil -- hence the "undefined method keys..." error message.
Another solution, is to use a convenience method that Rails adds to the Hash class: with_indifferent_access.
If you define your lookup table like this (I'm omitting the guts of it), then you can access this Hash with either String keys or Symbol keys, and doing #input2.to_sym won't be necessary:
CONVERSIONS = {
...
}.with_indifferent_access
My production database uses S3 and ActiveRecord to store images.
Since some time (could be related to the rails 6 upgrade but im not sure) a lot of the older images don't show their variants. Some newer ones however do. So it's not a general issue.
What puzzles me though, is that the non-variant image does show always
<p>
Variant, does not show
</p>
<%= image_tag #asset.image.variant(resize_to_fit: [200,200]) %>
<hr>
<p>
Original, shows
</p>
<%= image_tag #asset.image %>
<hr>
The log shows:
ActiveStorage::Blob Load (0.6ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 23], ["LIMIT", 1]]
S3 Storage (46.9ms) Checked if file exists at key: variants/assets/images/000/000/057/original/HOMEpg_PromoProd_990x660_microsite-Xplory.png/571109d233f5604a00cda0d8b8112d86e0bda9ff3c03f83cd9b25edbaf2dbed8 (no)
S3 Storage (320.9ms) Downloaded file from key: assets/images/000/000/057/original/HOMEpg_PromoProd_990x660_microsite-Xplory.png
Completed 500 Internal Server Error in 374ms (ActiveRecord: 0.6ms | Allocations: 29916)
ActiveStorage::IntegrityError (ActiveStorage::IntegrityError):
activestorage (6.0.2.1) lib/active_storage/downloader.rb:39:in `verify_integrity_of'
activestorage (6.0.2.1) lib/active_storage/downloader.rb:14:in `block in open'
activestorage (6.0.2.1) lib/active_storage/downloader.rb:24:in `open_tempfile'
activestorage (6.0.2.1) lib/active_storage/downloader.rb:12:in `open'
activestorage (6.0.2.1) lib/active_storage/service.rb:86:in `open'
activestorage (6.0.2.1) app/models/active_storage/blob.rb:219:in `open'
activestorage (6.0.2.1) app/models/active_storage/variant.rb:99:in `process'
activestorage (6.0.2.1) app/models/active_storage/variant.rb:67:in `processed'
activestorage (6.0.2.1) app/controllers/active_storage/representations_controller.rb:12:in `show'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:196:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.2.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.2.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.2.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.2.1) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (6.0.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:51:in `dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:837:in `call'
rack (2.1.2) lib/rack/tempfile_reaper.rb:17:in `call'
rack (2.1.2) lib/rack/etag.rb:27:in `call'
rack (2.1.2) lib/rack/conditional_get.rb:27:in `call'
rack (2.1.2) lib/rack/head.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.1.2) lib/rack/session/abstract/id.rb:269:in `context'
rack (2.1.2) lib/rack/session/abstract/id.rb:263:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.2.1) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web-console (4.0.1) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.1) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.5.0) lib/request_store/middleware.rb:19:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.1.2) lib/rack/method_override.rb:24:in `call'
rack (2.1.2) lib/rack/runtime.rb:24:in `call'
activesupport (6.0.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.1.2) lib/rack/sendfile.rb:113:in `call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
webpacker (4.2.2) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.2.1) lib/rails/engine.rb:526:in `call'
puma (3.12.2) lib/puma/configuration.rb:227:in `call'
puma (3.12.2) lib/puma/server.rb:674:in `handle_request'
puma (3.12.2) lib/puma/server.rb:476:in `process_client'
puma (3.12.2) lib/puma/server.rb:334:in `block in run'
puma (3.12.2) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
I researched IntegrityError a but and understand what is is about but that's it.
So first of all I'd like to understand what happens here and why variants are broken.
Second I would like to know if I can remedy that in some way...
I use vips but I uncommented it and it didn't change anything.
I hope you can help me, I've been following this rails guide: https://edgeguides.rubyonrails.org/active_storage_overview.html step by step to implement active storage with Azure but I'm having trouble uploading the file.
It keeps throwing this error: ActiveStorage::IntegrityError (ActiveStorage::IntegrityError)
The log displays this:
Processing by SliderController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"nx5HaniUlhwMBjtJPXW9safsafw6oT7PDog4aDg0XPC8Yasfas+T57ZYP0NJ7xWMI6halogBy0VO3Sg==", "slider"=>{"key"=>"home", "image"=>#<ActionDispatch::Http::UploadedFile:0xd5151f8 #tempfile=#<Tempfile:C:/Users/user/AppData/Local/Temp/RackMultipart20180827-34920-1ulxtdy.jpg>, #original_filename="30714520_1071308403021677_2686322307856596992_n.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"slider[image]\"; filename=\"30714520_1071308403021677_2686322307856596992_n.jpg\"\r\nContent-Type: image/jpeg\r\n">, "content"=>"asxa", "text2"=>"asxs", "link"=>"", "button"=>"More..."}, "commit"=>"Crete Slider"}
AzureStorage Storage (559.5ms) Uploaded file to key: yx4Qm4HA4wD9Ux7P3VhPqEFv (checksum: LO4ccLCw2J1w5TKgyxGG1g==)
Completed 500 Internal Server Error in 573ms (ActiveRecord: 0.0ms)
ActiveStorage::IntegrityError (ActiveStorage::IntegrityError)
activestorage (5.2.1) lib/active_storage/service/azure_storage_service.rb:25:in `rescue in block in upload'
activestorage (5.2.1) lib/active_storage/service/azure_storage_service.rb:22:in `block in upload'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.1) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `instrument'
activestorage (5.2.1) lib/active_storage/service.rb:118:in `instrument'
activestorage (5.2.1) lib/active_storage/service/azure_storage_service.rb:21:in `upload'
activestorage (5.2.1) app/models/active_storage/blob.rb:155:in `upload'
activestorage (5.2.1) app/models/active_storage/blob.rb:53:in `block in build_after_upload'
activestorage (5.2.1) app/models/active_storage/blob.rb:48:in `tap'
activestorage (5.2.1) app/models/active_storage/blob.rb:48:in `build_after_upload'
activestorage (5.2.1) app/models/active_storage/blob.rb:61:in `create_after_upload!'
activestorage (5.2.1) lib/active_storage/attached.rb:23:in `create_blob_from'
activestorage (5.2.1) lib/active_storage/attached/one.rb:24:in `attach'
activestorage (5.2.1) lib/active_storage/attached/macros.rb:37:in `imagen='
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:51:in `public_send'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:51:in `_assign_attribute'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:44:in `block in _assign_attributes'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:43:in `each'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:43:in `_assign_attributes'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:23:in `_assign_attributes'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:35:in `assign_attributes'
activerecord (5.2.1) lib/active_record/core.rb:314:in `initialize'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:in `new'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:in `new'
cancancan (2.2.0) lib/cancan/controller_resource_builder.rb:6:in `build_resource'
cancancan (2.2.0) lib/cancan/controller_resource_loader.rb:104:in `load_resource_instance'
cancancan (2.2.0) lib/cancan/controller_resource_loader.rb:15:in `load_resource'
cancancan (2.2.0) lib/cancan/controller_resource.rb:31:in `load_and_authorize_resource'
cancancan (2.2.0) lib/cancan/controller_resource.rb:15:in `block in add_before_action'
activesupport (5.2.1) lib/active_support/callbacks.rb:426:in `instance_exec'
activesupport (5.2.1) lib/active_support/callbacks.rb:426:in `block in make_lambda'
activesupport (5.2.1) lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
activesupport (5.2.1) lib/active_support/callbacks.rb:199:in `block in halting'
activesupport (5.2.1) lib/active_support/callbacks.rb:513:in `block in invoke_before'
activesupport (5.2.1) lib/active_support/callbacks.rb:513:in `each'
activesupport (5.2.1) lib/active_support/callbacks.rb:513:in `invoke_before'
activesupport (5.2.1) lib/active_support/callbacks.rb:131:in `run_callbacks'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.1) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.1) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.1) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:840:in `call'
rack (2.0.5) lib/rack/tempfile_reaper.rb:15: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'
actionpack (5.2.1) lib/action_dispatch/http/content_security_policy.rb:18: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.2.1) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.1) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.1) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.4.1) lib/request_store/middleware.rb:19:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/request_id.rb:27: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.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
railties (5.2.1) lib/rails/engine.rb:524:in `call'
rack (2.0.5) lib/rack/handler/webrick.rb:86:in `service'
C:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
C:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
C:/RailsInstaller/Ruby2.3.3/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'
I followed the guide step by step but still the same error, Anyone can help me and explain me what I'm missing? Thanks
I am updating to activestorage in rails 5.2 and am getting a "
undefined method `[]=' for nil:NilClass" in my create action.
I think the problem has to do with my whitelisted params. I tried to follow the guides but still cannot figure out what I am missing.
My model has has_many_attached :images
My controller has
def create
#product = Product.new(product_params)
#product.images.attach(params[:product][:images])
if #product.save
redirect_to #product, notice: 'Product was successfully created.'
else
render :new
end
end
private
def product_params
params.require(:product).permit(:name, :description, :category_id, :tag_list, :partialone, :partialtwo, :partialthree, :shape, :earrings, :metalweight, :sizeone, :sizetwo, :metal, :totalweightone, :totalweighttwo, :meleequant, review_attributes: [:id, :rating, :text, :author, :name], images: [] )
end
Here is the full trace:
acts-as-taggable-on (5.0.0) lib/acts_as_taggable_on/taggable/core.rb:206:in process_dirty_object'
acts-as-taggable-on (5.0.0) lib/acts_as_taggable_on/taggable/core.rb:184:inset_tag_list_on'
acts-as-taggable-on (5.0.0) lib/acts_as_taggable_on/taggable/core.rb:45:in tag_list='
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:51:inpublic_send'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:51:in _assign_attribute'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:44:inblock in _assign_attributes'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:43:in each'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:43:in_assign_attributes'
activerecord (5.2.1) lib/active_record/attribute_assignment.rb:23:in _assign_attributes'
activemodel (5.2.1) lib/active_model/attribute_assignment.rb:35:inassign_attributes'
activerecord (5.2.1) lib/active_record/core.rb:314:in initialize'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:innew'
activerecord (5.2.1) lib/active_record/inheritance.rb:66:in new'
activerecord (5.2.1) lib/active_record/persistence.rb:52:increate!'
app/controllers/products_controller.rb:65:in create'
actionpack (5.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:insend_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:194:in process_action'
actionpack (5.2.1) lib/action_controller/metal/rendering.rb:30:inprocess_action'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:42:in block in process_action'
activesupport (5.2.1) lib/active_support/callbacks.rb:132:inrun_callbacks'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:41:in process_action'
actionpack (5.2.1) lib/action_controller/metal/rescue.rb:22:inprocess_action'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:34:in block in process_action'
activesupport (5.2.1) lib/active_support/notifications.rb:168:inblock in instrument'
activesupport (5.2.1) lib/active_support/notifications/instrumenter.rb:23:in instrument'
activesupport (5.2.1) lib/active_support/notifications.rb:168:ininstrument'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:32:in process_action'
actionpack (5.2.1) lib/action_controller/metal/params_wrapper.rb:256:inprocess_action'
activerecord (5.2.1) lib/active_record/railties/controller_runtime.rb:24:in process_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:134:inprocess'
actionview (5.2.1) lib/action_view/rendering.rb:32:in process'
actionpack (5.2.1) lib/action_controller/metal.rb:191:indispatch'
actionpack (5.2.1) lib/action_controller/metal.rb:252:in dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:52:indispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:34:in serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:52:inblock in serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in each'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:inserve'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:840:in call'
warden (1.2.7) lib/warden/manager.rb:36:inblock in call'
warden (1.2.7) lib/warden/manager.rb:35:in catch'
warden (1.2.7) lib/warden/manager.rb:35:incall'
rack (2.0.5) lib/rack/tempfile_reaper.rb:15:in call'
rack (2.0.5) lib/rack/etag.rb:25:incall'
rack (2.0.5) lib/rack/conditional_get.rb:38:in call'
rack (2.0.5) lib/rack/head.rb:12:incall'
actionpack (5.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in call'
rack (2.0.5) lib/rack/session/abstract/id.rb:232:incontext'
rack (2.0.5) lib/rack/session/abstract/id.rb:226:in call'
actionpack (5.2.1) lib/action_dispatch/middleware/cookies.rb:670:incall'
activerecord (5.2.1) lib/active_record/migration.rb:559:in call'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:28:inblock in call'
activesupport (5.2.1) lib/active_support/callbacks.rb:98:in run_callbacks'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:26:incall'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in call'
actionpack (5.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:61:incall'
web-console (3.5.1) lib/web_console/middleware.rb:135:in call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:inblock in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:incall'
actionpack (5.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in call'
railties (5.2.1) lib/rails/rack/logger.rb:38:incall_app'
railties (5.2.1) lib/rails/rack/logger.rb:26:in block in call'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:inblock in tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:28:in tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:intagged'
railties (5.2.1) lib/rails/rack/logger.rb:26:in call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:incall'
actionpack (5.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in call'
request_store (1.4.1) lib/request_store/middleware.rb:19:incall'
actionpack (5.2.1) lib/action_dispatch/middleware/request_id.rb:27:in call'
rack (2.0.5) lib/rack/method_override.rb:22:incall'
rack (2.0.5) lib/rack/runtime.rb:22:in call'
activesupport (5.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:incall'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in call'
actionpack (5.2.1) lib/action_dispatch/middleware/static.rb:127:incall'
rack (2.0.5) lib/rack/sendfile.rb:111:in call'
webpacker (3.5.5) lib/webpacker/dev_server_proxy.rb:22:inperform_request'
rack-proxy (0.6.4) lib/rack/proxy.rb:57:in call'
railties (5.2.1) lib/rails/engine.rb:524:incall'
rack (2.0.5) lib/rack/handler/webrick.rb:86:in service'
/Users/Joseph/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/webrick/httpserver.rb:140:inservice'
/Users/Joseph/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/webrick/httpserver.rb:96:in run'
/Users/Joseph/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/webrick/server.rb:290:inblock in start_thread'
For some reason, I think the problem is with "images: []" in the whitelisted params but am not sure. Any ideas? Thank you.
I'm new to ruby on rails and currently working on a web application which uses the 'rspotify' gem to interact with the Spotify API.
I have a controller called 'genre' which I use to direct my search results from the index page. However, it won't let me initialize any variables inside the index function.
This is what my controller looks like
# genre_controller.rb
def index
if params[:search]
#genres = RSpotify::Recommendations.generate(limit: 20, seed_genres: ['country'])
# render :json => #songs
else
redirect_to root_path
end
end
This is what my my index page looks like
<h1>Genre#index</h1>
<p>Find me in app/views/genre/index.html.erb</p>
<h1 class="page-header">Music Matching <%= params[:search] %></h1>
<ul>
<% #music.each do |music| %>
<li><%= music.name %> | <%= link_to "Show", genre_path(music.id) %></li>
<% end %>
</ul>
This is what my routes look like
get 'genre/index'
get 'genre/show', to:'genre#show', as: 'genre'
get 'site/index'
root 'site#index'
I get an error on line 4 of my genre controller, where I call the RSpotify method. Any variable I try to instantiate there returns a NoErrorMethod.
Any help is appreciated, thanks!
Edit:
Here's the exception I get from the console
NoMethodError (undefined method `[]' for nil:NilClass):
app/controllers/genre_controller.rb:4:in `index'
Started GET "/genre/index?utf8=%E2%9C%93&search=hello" for 127.0.0.1 at 2018-02-19 16:14:59 -0800
Processing by GenreController#index as HTML
Parameters: {"utf8"=>"✓", "search"=>"hello"}
Completed 500 Internal Server Error in 295ms
Here's the full tracestack from the exception
rspotify (1.27.0) lib/rspotify/recommendations.rb:101:in `initialize'
rspotify (1.27.0) lib/rspotify/recommendations.rb:97:in `new'
rspotify (1.27.0) lib/rspotify/recommendations.rb:97:in `generate'
app/controllers/genre_controller.rb:4:in `index'
actionpack (5.1.4) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.1.4) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.4) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.1.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.1.4) lib/active_support/callbacks.rb:131:in `run_callbacks'
actionpack (5.1.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.4) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.4) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.1.4) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.4) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.4) lib/active_support/notifications.rb:166:in `instrument'
actionpack (5.1.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.4) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
activerecord (5.1.4) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
actionpack (5.1.4) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.4) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.4) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.4) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:834:in `call'
rack (2.0.4) lib/rack/etag.rb:25:in `call'
rack (2.0.4) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.4) lib/rack/head.rb:12: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'
actionpack (5.1.4) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.4) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.4) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.4) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.4) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.4) 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.4) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.4) lib/rack/method_override.rb:22:in `call'
rack (2.0.4) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
railties (5.1.4) lib/rails/engine.rb:522:in `call'
puma (3.11.2) lib/puma/configuration.rb:225:in `call'
puma (3.11.2) lib/puma/server.rb:624:in `handle_request'
puma (3.11.2) lib/puma/server.rb:438:in `process_client'
puma (3.11.2) lib/puma/server.rb:302:in `block in run'
puma (3.11.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
I got a similar error as above when I tried to connect to the Spotify API. The documentation on rspotify missed out the fact that you need to run the authenticate method before you do anything with the API.
i.e.
RSpotify.authenticate("<your_client_id>", "<your_client_secret>")