I'm trying to render a view outside of a controller and can't seem to get i18n to work. I'm using the feature noted here, https://github.com/rails/rails/issues/18409, https://evilmartians.com/chronicles/new-feature-in-rails-5-render-views-outside-of-actions, https://api.rubyonrails.org/classes/ActionController/Renderer.html
ABCController.render :index, assigns: {myvar: '12345'}
This is an example of what I'm doing. The view renders fine in English and Spanish when accessed normally through a controller. I'm actually using that render command inside another controller action to pass it to WickedPDF. However, it always renders English.
Any help would be appreciated. I looked through the documentation for render and https://github.com/rails/rails/issues/18409 this pull request.
CodePudding user response:
I couldn't try this, but it can solve your problem.
I18n.with_locale('es') do
ABCController.render :index, assigns: { my_var: '12345' }
end
CodePudding user response:
Figured it out. I wasn't setting locale for the one action I needed it. It was a stupid oversight on my part. It works just fine with I18n localization as long as you do it correctly. Make sure all controller actions are properly localized and render works fine. I thought I had my bases covered but I clearly didn't.