You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into this very surprising issue last week. I added the attribute open to a model and then to the edit form of that model.
Upon opening that edit form I saw an ArgumentError and the stack trace indicates that somehow the method open from open-uri got called.
The stack trace also included a monkey patch from the ransack gem so it was a bit of bad luck that I ran into this issue. They replaced the public_send call with send which is why this bug does not appear in a normal rails installation with draper.
So I tried to create a bug report for them and played detective for way too long 🕵️. Then I saw it! We also use the decorates_assigned method in the culprit controller and the object that gets passed to the form is actually a Decorator object and not really the model.
Probably I will open an issue in the ransack project as well but I believe that this handling of the send behaviour is undesired. Of course I can work around the bug for this particular case but there might be other metaprogramming somewhere that uses send and not public_send on decorated objects - especially in the context of views.
Personally, I tested this with draper 3.x and 4.x.
# frozen_string_literal: truerequire"bundler/inline"gemfile(true)dosource"https://rubygems.org"git_source(:github){ |repo| "https://github.com/#{repo}.git"}# Activate the gem you are reporting the issue against.gem"rails",'~> 5.2'# Activate the gem you are reporting the issue against.gem"sqlite3"gem'hamlit'gem'discard'# loading/requiring ransack fails without this. No idea why.gem'draper'gem'ransack'endrequire"active_record"require"rack/test"require"action_controller/railtie"classTestApp < Rails::Applicationconfig.root=__dir__# config.hosts << "example.org"config.session_store:cookie_store,key: "cookie_store_key"secrets.secret_key_base="secret_key_base"config.logger=Logger.new($stdout)Rails.logger=config.loggerroutes.drawdoresources:commentsendend# This connection will do for database-independent bug reports.ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")ActiveRecord::Base.logger=Logger.new(STDOUT)ActiveRecord::Schema.definedocreate_table:comments,force: truedo |t|
t.string:open,default: 'false't.string:author_nameendendclassComment < ActiveRecord::BaseincludeDraper::DecoratableendclassCommentDecorator < Draper::Decoratordelegate_allendclassCommentsController < ActionController::BaseincludeRails.application.routes.url_helpersincludeDraper::DecoratesAssigned# grrr not working# decorates_assigned :commentdefindexrenderplain: "Home"enddefedit@comment=Comment.find(params[:id]).decoratetemplate=<<ERB<%=form_for(@comment)do |f| %><%=f.text_field:open%><%end%>ERBrenderinline: template,layout: falseendendrequire"minitest/autorun"classBugTest < Minitest::TestincludeRack::Test::Methodsdeftest_smokeget"/comments"assertlast_response.ok?enddeftest_returns_successcomment=Comment.create!(open: 'true')get"/comments/#{comment.id}/edit"assertlast_response.ok?endprivatedefappRails.applicationendend
The text was updated successfully, but these errors were encountered:
klyonrad
changed the title
Sending problematic method names (open, format) to decorated rails objects send to Kernel (conflicts with ransack)
Sending problematic method names (open, format) to decorated rails objects sends to Kernel (conflicts with ransack)
Aug 18, 2020
I ran into this very surprising issue last week. I added the attribute
open
to a model and then to the edit form of that model.Upon opening that edit form I saw an ArgumentError and the stack trace indicates that somehow the method
open
fromopen-uri
got called.The stack trace also included a monkey patch from the
ransack
gem so it was a bit of bad luck that I ran into this issue. They replaced thepublic_send
call withsend
which is why this bug does not appear in a normal rails installation with draper.So I tried to create a bug report for them and played detective for way too long 🕵️. Then I saw it! We also use the
decorates_assigned
method in the culprit controller and the object that gets passed to the form is actually a Decorator object and not really the model.Probably I will open an issue in the
ransack
project as well but I believe that this handling of thesend
behaviour is undesired. Of course I can work around the bug for this particular case but there might be other metaprogramming somewhere that usessend
and notpublic_send
on decorated objects - especially in the context of views.Appendix
Problematic Draper behaviour
rails integration test
Personally, I tested this with draper 3.x and 4.x.
Stacktrace
test leads to
The text was updated successfully, but these errors were encountered: