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 back then. I added the attribute open to a model and then to the edit form of that model in a rails project that has draper and ransack installed.
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 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.
So I am creating the bug report here as well so that maybe it can be evaluated if the monkey patch for the form helper method is still necessary.
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
I first reported this in the draper project but received no feedback, so I thought I'd share this here as well - for the rare case that someone else trips into this.
I ran into this very surprising issue back then. I added the attribute
open
to a model and then to the edit form of that model in a rails project that hasdraper
andransack
installed.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 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.So I am creating the bug report here as well so that maybe it can be evaluated if the monkey patch for the form helper method is still necessary.
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: