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.0.0, Rails 6.1.3 - wrong number of arguments (given 1, expected 0) #3342

Closed
lfuszara1 opened this issue Feb 20, 2021 · 9 comments
Closed

Comments

@lfuszara1
Copy link

ArgumentError in RailsAdmin::MainController#new
wrong number of arguments (given 1, expected 0)

    def save(**) # :nodoc:
      SuppressorRegistry.suppressed[self.class.name] ? true : super
    end

https://rubyreferences.github.io/rubychanges/3.0.html#keyword-arguments-are-now-fully-separated-from-positional-arguments


Problem is probably connected with new way of declaring keyword arguments.

def old_style(name, options = {})
end

def new_style(name, **options)
end
@toddsiegel
Copy link

As far as I can tell this is fixed on master, but not released yet.

In the meantime, I have my Gemfile pointing there: gem 'rails_admin', github: 'sferik/rails_admin'. So far it's resolved the issue (without introducing new ones).

@RocKhalil
Copy link
Contributor

@toddsiegel yes and no.
It actually fails when you have a custom action and its related views.

@mshibuya
Copy link
Member

@RocKhalil I could not reproduce that, how does the custom action look like?
Can you provide reproducible code?

@RocKhalil
Copy link
Contributor

@mshibuya sorry for the late reply, here's an example:

action:

RailsAdmin.config do |config|
  config.actions do

    member :my_custom_action do
      pjax false # very important when using a React component
      i18n_key :my_custom_action
      link_icon 'fa fa-music'
      only [Song]
      http_methods { [:post, :get] }

      controller do
        proc do
          if request.get?
            if request.format.json?
              render json: { data: @object.my_custom_action }, status: :ok
            end
          elsif request.post?
            render json: {
              success: @object.my_custom_action_with_params!(random_param: params[:random_param])
            },
            status: :ok
          end
        end
      end
    end

  end
end

And here's my view:

<%= javascript_pack_tag 'react-bundle' %>

<%= react_component("MyReactComponent", props: {
  customProps: @object.cutom_method(mode: :custom_mode)
}, prerender: false) %>

Of course, I've changed the method names, etc..
But, both:

@object.my_custom_action_with_params!(random_param: params[:random_param])
AND
@object.cutom_method(mode: :custom_mode)

are breaking. If you remove the named param and use @object.cutom_method(:custom_mode) instead, it will work.

@mshibuya
Copy link
Member

mshibuya commented Mar 3, 2021

I see, so the problem is in your code. You need to fix it yourself.

@mshibuya mshibuya closed this as completed Mar 3, 2021
@RocKhalil
Copy link
Contributor

@mshibuya how is the issue in my code ? :-p
If I move my code to another view, it runs perfectly. However, when it runs using Rails Admin's binding it throws an error.

@mshibuya
Copy link
Member

mshibuya commented Mar 3, 2021

Please forget about it, I found something suspicious.
https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/adapters/active_record/abstract_object.rb#L26-L28

@mshibuya mshibuya reopened this Mar 3, 2021
@mshibuya
Copy link
Member

mshibuya commented Mar 3, 2021

I've just pushed the fix to the master, please try and see if it works.

@RocKhalil
Copy link
Contributor

Yup, works like a charm !
Thanks for the quick update.

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

No branches or pull requests

4 participants