Commit 7695a3ac5d70299de65cfe3315cffb3fc866fc0a
1 parent
b536a5a6
Exists in
colab
and in
4 other branches
Fixed locale setting by user for turbolinks and devise
Signed-off-by: Daniel Miranda <danielkza2@gmail.com>
Showing
3 changed files
with
16 additions
and
6 deletions
Show diff stats
app/controllers/application_controller.rb
| @@ -10,8 +10,22 @@ class ApplicationController < ActionController::Base | @@ -10,8 +10,22 @@ class ApplicationController < ActionController::Base | ||
| 10 | before_filter :configure_permitted_parameters, if: :devise_controller? | 10 | before_filter :configure_permitted_parameters, if: :devise_controller? |
| 11 | before_filter :set_locale | 11 | before_filter :set_locale |
| 12 | 12 | ||
| 13 | + # This is necessary for correct devise routing with locales: https://github.com/plataformatec/devise/wiki/How-To:--Redirect-with-locale-after-authentication-failure | ||
| 14 | + def self.default_url_options | ||
| 15 | + merge_locale_to_options(super()) | ||
| 16 | + end | ||
| 17 | + | ||
| 18 | + # This happens after the *_url *_path helpers | ||
| 19 | + def default_url_options(options = {}) | ||
| 20 | + self.class.merge_locale_to_options(options) | ||
| 21 | + end | ||
| 22 | + | ||
| 13 | protected | 23 | protected |
| 14 | 24 | ||
| 25 | + def self.merge_locale_to_options(options) | ||
| 26 | + { locale: I18n.locale }.merge options | ||
| 27 | + end | ||
| 28 | + | ||
| 15 | # :nocov: | 29 | # :nocov: |
| 16 | def configure_permitted_parameters | 30 | def configure_permitted_parameters |
| 17 | devise_parameter_sanitizer.for(:sign_up) << :name | 31 | devise_parameter_sanitizer.for(:sign_up) << :name |
| @@ -29,8 +43,4 @@ class ApplicationController < ActionController::Base | @@ -29,8 +43,4 @@ class ApplicationController < ActionController::Base | ||
| 29 | end | 43 | end |
| 30 | end | 44 | end |
| 31 | 45 | ||
| 32 | - # This happens after the *_url *_path helpers | ||
| 33 | - def default_url_options(options = {}) | ||
| 34 | - { locale: I18n.locale == I18n.default_locale ? nil : I18n.locale }.merge options | ||
| 35 | - end | ||
| 36 | end | 46 | end |
app/views/layouts/application.html.erb
| @@ -78,7 +78,7 @@ | @@ -78,7 +78,7 @@ | ||
| 78 | </a> | 78 | </a> |
| 79 | <ul class="dropdown-menu" role="menu"> | 79 | <ul class="dropdown-menu" role="menu"> |
| 80 | <% I18n.available_locales.each do |locale| %> | 80 | <% I18n.available_locales.each do |locale| %> |
| 81 | - <li><%= link_to(locale.to_s, url_for(locale: locale)) %></li> | 81 | + <li><%= link_to(locale.to_s, url_for(locale: locale), data: { no_turbolink: true }) %></li> |
| 82 | <% end %> | 82 | <% end %> |
| 83 | </ul> | 83 | </ul> |
| 84 | </li> | 84 | </li> |
spec/controllers/reading_groups_controller_spec.rb
| @@ -121,7 +121,7 @@ describe ReadingGroupsController, :type => :controller do | @@ -121,7 +121,7 @@ describe ReadingGroupsController, :type => :controller do | ||
| 121 | delete :destroy, :id => @subject.id | 121 | delete :destroy, :id => @subject.id |
| 122 | end | 122 | end |
| 123 | 123 | ||
| 124 | - it { is_expected.to redirect_to new_user_session_path } | 124 | + it { is_expected.to redirect_to new_user_session_url } |
| 125 | end | 125 | end |
| 126 | end | 126 | end |
| 127 | 127 |