module ApplicationHelper
def t(*a)
translate(*a)
end
end
Case 1 :- t('views.home.welcome_updated', default: 'Updated') => Getting Error: (wrong number of arguments (given 2, expected 1))
Case 2 :- t('views.welcome') => Working fine
Ruby Version: 3.0.6
Rails Version: 6.1.7.6
What is the problem with above code?
Both case 1 & 2 working fine in ruby 2.7. i am getting error after upgraded ruby version to 3
customize t method to
module ApplicationHelper
def t(key, **options)
args = [key]
args.push options if options.present?
translate(*a)
end
end
But this is also not working
translate(key, **options)but your*aonly captures positional arguments, i.e. thekeypart. In Ruby 3.x, you have to handle keyword arguments explicitly via**or use...as shown below.TranslationHelperdefines both,translateandt, so maybe you already have both variants and are needlessly re-definingt.