Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 3 Bug image_pack_tag "wrong number of arguments (given 2, expected 1)" #312

Closed
matthieu-delrive opened this issue Sep 7, 2021 · 7 comments · Fixed by #318
Closed

Comments

@matthieu-delrive
Copy link

matthieu-delrive commented Sep 7, 2021

Hello

I’m trying to update to ruby 3 and get an error on image_pack_tag only on form on active admin

/usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/helper.rb:52:in image_pack_tag,
/usr/local/bundle/gems/arbre-1.4.0/lib/arbre/element.rb:182:in method_missing,
/usr/local/bundle/gems/arbre-1.4.0/lib/arbre/rails/forms.rb:37:in method_missing,
...

How to reproduce
Add image_pack_tag with more than one parameter
and go on the creation or edition web page
Example

ActiveAdmin.register Post do
  menu parent: "Blog", priority: 1

  form do |f|
    panel "Markup" do
      image_pack_tag("cat.jpg", class: "title")
    end
  end
end

I found a fix to my case, on method missing in file arbre/rails/forms.rb
Replacing

def method_missing(method, *args, &block)

To

def method_missing(method, *args, **kwargs, &block)

And

proxy_call_to_form(method, *args, &block)

to

proxy_call_to_form(method, *args, **kwargs, &block)

Ruby 3
Rails 6.1
Active admin 2.9

@colinux
Copy link

colinux commented Sep 17, 2021

Same issue & fix with other helpers like t , ie t("translate-key", count: 2)
In this case a workaround is to directly call helpers.t

@tagliala
Copy link
Contributor

I've run into this issue as well when trying to upgrade ro Rails 7 / Ruby 3

Wasn't able to reproduce on 6.1 / Ruby 3

I think this may be related to #268

Probably it is not covered by specs

In this case a workaround is to directly call helpers.t

I've used I18n.t

@omitter
Copy link

omitter commented Dec 23, 2021

I have the same issue with Rails 6.0 / Ruby 3.
Adding **kwargs fixes it for me.
This is probably also related to #205.

@tagliala
Copy link
Contributor

@omitter
Copy link

omitter commented Dec 23, 2021

I run the tests on my computer and they also worked. Even when I changed some labels to t("something", scope: "something"). That means the tests don't cover the current error. Unfortunately I don't see how to fix them.

I suspect some problem with ruby2_keywords, which was meant as a temporary solution anyway. I reverted (plus some smaller changes) the commit that introduced it (see #205) and now it's working again. Tested it on ruby 2.5 and 3.0. So why did we need that in the first place. Maybe @deivid-rodriguez can remember? If you like I can send you PR and you can test it further.

Another option would be to drop ruby 2.5 and 2.6 support completely. 2.6 is reaching EOL very soon and Rails 7, which is a dependency inside the Gemfile, is requiring >= 2.7 anyway.

@javierjulio
Copy link
Member

I'm encountering now the same issue after upgrading to Ruby 3.0. I did get a deprecation warning on Ruby 2.7. It does occur from calling a helper method that accepts kwargs. I will look into adding a failing case in the integration tests soon.

@javierjulio
Copy link
Member

Yesterday, I was able to get a failing test on Ruby 3.0 through an ActiveAdmin form calling a helper method, just as OP reported. I couldn't figure out how to replicate this on just Arbre's test suite though but having that failure on ActiveAdmin may help establish that how to do that. I'll submit that for ActiveAdmin in the meantime.

Worth noting if the helper method takes keyword arguments but they are all optional and none are given, no error occurs on Ruby 3.0 but if any kwargs are specified (required or not), it will fail with the argument error reported.

javierjulio added a commit to javierjulio/activeadmin that referenced this issue Feb 4, 2022
When a helper method accepts kwargs and they are given, this causes a failure in Ruby 3.0.

> wrong number of arguments (given 2, expected 1) (ActionView::Template::Error)
> ./tmp/test_apps/rails_61/app/helpers/time_helper.rb:3:in `format_time'

If the keyword arguments are all optional and NOT given, then no error occurs.

activeadmin/arbre#312
javierjulio added a commit to javierjulio/activeadmin that referenced this issue Feb 4, 2022
When a helper method accepts kwargs and they are given, this causes a failure in Ruby 3.0.

> wrong number of arguments (given 2, expected 1) (ActionView::Template::Error)
> ./tmp/test_apps/rails_61/app/helpers/time_helper.rb:3:in `format_time'

If the keyword arguments are all optional and NOT given, then no error occurs.

activeadmin/arbre#312
javierjulio added a commit to javierjulio/activeadmin that referenced this issue Feb 8, 2022
When a helper method accepts kwargs and they are given, this causes a failure in Ruby 3.0.

> wrong number of arguments (given 2, expected 1) (ActionView::Template::Error)
> ./tmp/test_apps/rails_61/app/helpers/time_helper.rb:3:in `format_time'

If the keyword arguments are all optional and NOT given, then no error occurs.

activeadmin/arbre#312
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants