vendredi 26 juin 2015

Rails- form_for url overrides default_form_options and renders default locale

This is my form:

= form_for @example, url: new_funnel_example_path, method: :get do |f| // here goes my form content end

and application_controller.rb

before_filter :set_locale

def set_locale
  I18n.locale = params[:locale] || I18n.default_locale
end

def default_url_options(options = {})
  return { locale: I18n.locale }.merge options
end

Root Cause: My form_for url helper overrides the default_url_options and because set_locale is invoked in before_filter(before every action call) it sets I18n.locale to I18n.default_locale and thereby changing the app to default locale .

It might work if I pass params[:locale] as a hidden variable - that would be tedious and will look ugly.So is there a neat fix for this ?

Aucun commentaire:

Enregistrer un commentaire