Я сталкиваюсь с ошибкой, которая говорит:
ActionView::Template::Error:
wrong number of arguments (given 1, expected 0)
Вот соответствующий код в модели:
class LocationProgram < ApplicationRecord
include CtasMixin
belongs_to :location, inverse_of: :location_programs
belongs_to :program, inverse_of: :location_programs
belongs_to :thumbnail, class_name: 'ImageAsset', foreign_key: :thumbnail_asset_id
has_many :content_images, -> { order('sequence ASC NULLS LAST') }, as: :contentable, dependent: :destroy
has_cta :ecommerce_cta, "buy-tickets"
%w(content_images thumbnail ecommerce_cta).each do |attr|
# this code below raises the error
# line below is location_program.rb:50
define_method(attr) { program&.send(attr) || super(attr) }
end
...
end
class Program < ApplicationRecord
include CtasMixin
has_many :location_programs, dependent: :destroy, inverse_of: :program
has_many :locations, through: :location_programs
belongs_to :thumbnail, class_name: 'ImageAsset', foreign_key: :thumbnail_asset_id
has_many :content_images, -> { order('sequence ASC NULLS LAST') }, as: :contentable, dependent: :destroy
has_cta :ecommerce_cta, "buy-tickets"
...
end
module CtasMixin
extend ActiveSupport::Concern
module ClassMethods
def has_cta(attr_name, default_slug = '')
belongs_to attr_name, class_name: 'CallToAction'
define_method "#{attr_name}_default_object" do
CallToAction.find_by(slug: default_slug) if default_slug.present?
end
define_method "#{attr_name}_value" do
# Line below is line 35
send(attr_name).try(:value_t) || send("#{attr_name}_default_value")
end
define_method "#{attr_name}_default_value" do
if default_slug.present?
cta = send("#{attr_name}_default_object")
cta ? cta.value_t : default_slug.titleize
end
end
end
end
end
Я недавно обновил свою версию рельсов с 5.0 до 5.2 и это случилось, когда я попытался запустить rspec
.
Я не слишком уверен, что здесь происходит, я подозреваю, что это как-то связано с моим CtasMixin
беспокойством. Я пытался искать вокруг, но я не смог выяснить ничего, что связано с моей проблемой здесь. Буду очень признателен за любую помощь!
Полная трассировка стека:
Failure/Error: define_method(attr) { program&.send(attr) || super(attr) }
ActionView::Template::Error:
wrong number of arguments (given 1, expected 0)
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activerecord-5.2.4.1/lib/active_record/associations/builder/association.rb:107:in `ecommerce_cta'
# ./app/models/location_program.rb:50:in `block (2 levels) in <class:LocationProgram>'
# ./app/models/concerns/ctas_mixin.rb:35:in `block in has_cta'
# ./app/views/site/locations/programs/show.html.erb:23:in `_app_views_site_locations_programs_show_html_erb__1085825840410338714_70185561273160'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/template.rb:159:in `block in render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:170:in `instrument'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/template.rb:354:in `instrument_render_template'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/template.rb:157:in `render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `block in instrument'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `instrument'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:52:in `render_template'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/renderer/template_renderer.rb:16:in `render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/renderer/renderer.rb:44:in `render_template'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/renderer/renderer.rb:25:in `render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/rendering.rb:103:in `_render_template'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/streaming.rb:219:in `_render_template'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/rendering.rb:84:in `render_to_body'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/rendering.rb:52:in `render_to_body'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/renderers.rb:142:in `render_to_body'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/abstract_controller/rendering.rb:25:in `render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/rendering.rb:36:in `render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/core_ext/benchmark.rb:14:in `ms'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/instrumentation.rb:46:in `block in render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activerecord-5.2.4.1/lib/active_record/railties/controller_runtime.rb:31:in `cleanup_view_runtime'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/instrumentation.rb:45:in `render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/wicked_pdf-2.0.1/lib/wicked_pdf/pdf_helper.rb:46:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/wicked_pdf-2.0.1/lib/wicked_pdf/pdf_helper.rb:46:in `render_with_wicked_pdf'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/wicked_pdf-2.0.1/lib/wicked_pdf/pdf_helper.rb:30:in `render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/implicit_render.rb:35:in `default_render'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/andand-1.3.3/lib/andand.rb:60:in `me'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/abstract_controller/base.rb:194:in `process_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/rendering.rb:30:in `process_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:109:in `block in run_callbacks'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/sentry-raven-2.13.0/lib/raven/integrations/rails/controller_transaction.rb:7:in `block in included'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:118:in `instance_exec'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:136:in `run_callbacks'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/abstract_controller/callbacks.rb:41:in `process_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/rescue.rb:22:in `process_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `block in instrument'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:168:in `instrument'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/instrumentation.rb:32:in `process_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activerecord-5.2.4.1/lib/active_record/railties/controller_runtime.rb:24:in `process_action'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/abstract_controller/base.rb:134:in `process'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionview-5.2.4.1/lib/action_view/rendering.rb:32:in `process'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal.rb:191:in `dispatch'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_controller/metal.rb:252:in `dispatch'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/routing/route_set.rb:34:in `serve'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/journey/router.rb:52:in `block in serve'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/journey/router.rb:35:in `each'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/journey/router.rb:35:in `serve'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/routing/route_set.rb:840:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/route_downcaser-1.2.3/lib/route_downcaser/downcase_route_middleware.rb:42:in `_call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/route_downcaser-1.2.3/lib/route_downcaser/downcase_route_middleware.rb:11:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/scout_apm-2.6.6/lib/scout_apm/middleware.rb:17:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/warden-1.2.8/lib/warden/manager.rb:36:in `block in call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/warden-1.2.8/lib/warden/manager.rb:34:in `catch'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/warden-1.2.8/lib/warden/manager.rb:34:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/tempfile_reaper.rb:15:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/etag.rb:27:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/conditional_get.rb:27:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/head.rb:12:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/session/abstract/id.rb:266:in `context'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/session/abstract/id.rb:260:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/cookies.rb:670:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/railties-5.2.4.1/lib/rails/rack/logger.rb:38:in `call_app'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/railties-5.2.4.1/lib/rails/rack/logger.rb:26:in `block in call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/tagged_logging.rb:71:in `block in tagged'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/tagged_logging.rb:28:in `tagged'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/tagged_logging.rb:71:in `tagged'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/railties-5.2.4.1/lib/rails/rack/logger.rb:26:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/method_override.rb:24:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/runtime.rb:22:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activesupport-5.2.4.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-rewrite-1.5.1/lib/rack/rewrite.rb:24:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/actionpack-5.2.4.1/lib/action_dispatch/middleware/static.rb:127:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/font_assets-0.1.14/lib/font_assets/middleware.rb:17:in `block in call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/font_assets-0.1.14/lib/font_assets/middleware.rb:40:in `do_request'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/font_assets-0.1.14/lib/font_assets/middleware.rb:16:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/sendfile.rb:110:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/sentry-raven-2.13.0/lib/raven/integrations/rack.rb:51:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/railties-5.2.4.1/lib/rails/engine.rb:524:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/urlmap.rb:74:in `block in call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/urlmap.rb:58:in `each'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-2.2.2/lib/rack/urlmap.rb:58:in `call'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-test-1.1.0/lib/rack/mock_session.rb:29:in `request'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-test-1.1.0/lib/rack/test.rb:266:in `process_request'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-test-1.1.0/lib/rack/test.rb:129:in `custom_request'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/rack-test-1.1.0/lib/rack/test.rb:58:in `get'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/capybara-3.31.0/lib/capybara/rack_test/browser.rb:68:in `process'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/capybara-3.31.0/lib/capybara/rack_test/browser.rb:43:in `process_and_follow_redirects'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/capybara-3.31.0/lib/capybara/rack_test/browser.rb:23:in `visit'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/capybara-3.31.0/lib/capybara/rack_test/driver.rb:45:in `visit'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/capybara-3.31.0/lib/capybara/session.rb:278:in `visit'
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/capybara-3.31.0/lib/capybara/dsl.rb:58:in `block (2 levels) in <module:DSL>'
# ./spec/features/site/locations_pages_spec.rb:189:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# ArgumentError:
# wrong number of arguments (given 1, expected 0)
# /Users/mattvo/.rvm/gems/ruby-2.6.5/gems/activerecord-5.2.4.1/lib/active_record/associations/builder/association.rb:107:in `ecommerce_cta'