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 ActionView::Template::Error: wrong number of arguments error with keyword args #71

Open
taketo1113 opened this issue Feb 3, 2023 · 4 comments · May be fixed by #73
Open

Ruby 3.0 ActionView::Template::Error: wrong number of arguments error with keyword args #71

taketo1113 opened this issue Feb 3, 2023 · 4 comments · May be fixed by #73

Comments

@taketo1113
Copy link
Contributor

It raises the error of ActionView::Template::Error: wrong number of arguments when exec Cell::RailsExtensions::ViewModel#call with keyword args in ruby 3.0.

Steps to reproduce

ref: taketo1113@f7a9c66

# app/cells/song_cell.rb
class SongCell < Cell::ViewModel
  def with_title(with_title: '')
    "<h1>#{with_title}</h1>"
  end
end

# app/controllers/musician_controller.rb
class MusicianController < ActionController::Base
  def view_with_cell_with_call_keyword_args
    render inline: %{<%= cell("view_extensions_test/song", "A Tale That Wasn't Right").call(:with_title, with_title: 'test') %>}
  end
end

Expected behavior

It will render with_title cell with keyword args.

Actual behavior

It raises the below error.

ActionView::Template::Error: wrong number of arguments (given 1, expected 0)

It can't get with_title args of keyword args in SongCell#with_title.
Because Cell::RailsExtensions::ViewModel#call does not support keyword args.

It seems it is able to fix the args of Cell::RailsExtensions::ViewModel#call.

-      def call(*)
+      def call(*args, **kws)
         super.html_safe
       end

https://github.com/trailblazer/cells-rails/blob/master/lib/cell/rails.rb#L55

System configuration

  • ruby: 3.0.5
  • cells-rails: v0.1.5
  • cells: (github master branch)
@apotonick
Copy link
Member

Thanks @taketo1113 could you PR your branch?

@taketo1113
Copy link
Contributor Author

@apotonick Thanks to replay.

I created PR #72.

@apotonick
Copy link
Member

@taketo1113 would you like to fix the bug? I think you have to change *args to *args, **kws...?

@taketo1113
Copy link
Contributor Author

@apotonick PR (#72) is only adding test case.

I created #73 to fix Cell::RailsExtensions::ViewModel#call with keyword args.
but it fail test because it need to release the commit trailblazer/cells@88796e3 of cells gem.

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.

2 participants