undefined method `localized' for #<ActionDispatch::Routing::Mapper:
Tioneb12 opened this issue · 7 comments
I try to use your gem, but I'm newbie in rails...
Step by step, what have I do ?
1 - in routes.rb
localized do
resources :ways, only:[:index, :show], :shallow => true do
resources :tracks, only:[:index, :show], :shallow => true
resources :pois, only: [:index, :show, :new, :create, :edit, :update, :destroy]
end
end
2- Add the translations to my locales files, and... great... my routes are translated ;)
ways_en GET /ways(.:format) ways#index {:my_locale=>"en"}
ways_fr GET /voie(.:format) ways#index {:my_locale=>"fr"}
3 - Config some params in RouteTranslator via an initializer
RouteTranslator.config do |config|
config.available_locales = [:fr, :en]
config.hide_locale = true
config.locale_param_key = :locale
end
4 - Set locale in my application controller :
before_action :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
And I have this in config/application.rb
config.load_defaults 5.1
config.i18n.default_locale = :fr
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
Now I have this message : "undefined method `localized' for #<ActionDispatch::Routing::Mapper:"
What's happend ? Could you explain and help me ? Thks ;)
PS : I use friendly-id gem
Could you please post your Gemfile?
4 - Set locale in my application controller :
Don't do that
Thks for your help ;)
source 'https://rubygems.org'
ruby '2.4.3'
gem 'devise'
gem 'devise-i18n'
gem 'figaro'
gem 'geocoder'
gem 'jbuilder', '~> 2.0'
gem 'pg', '~> 0.21'
gem 'puma'
gem 'rails', '5.1.6'
gem 'redis'
gem 'activerecord-postgis-adapter'
gem 'autoprefixer-rails'
gem 'bootstrap-sass', '~> 3.3'
gem 'cloudinary'
gem 'font-awesome-sass', '~> 5.0.9'
gem 'friendly_id', '~> 5.1.0'
gem 'jquery-rails'
gem 'pg_search'
gem 'rgeo'
gem 'rgeo-activerecord'
gem 'rgeo-geojson'
gem 'route_translator'
gem 'sass-rails'
gem 'simple_form'
gem 'turbolinks', '~> 5.0.0'
gem 'uglifier'
gem 'webpacker'
group :development do
gem 'web-console', '>= 3.3.0'
end
group :development, :test do
gem 'pry-byebug'
gem 'pry-rails'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
Now I have this message : "undefined method `localized' for #<ActionDispatch::Routing::Mapper:"
where?
http://localhost:3000/ways for exemple
and no routes match for :
http://localhost:3000/pois/1
I'm sorry, I have restart the server and now... I don't have any errors... but the urls are not translates :(
I think we can close... sorry for your time ;)
I just must find how can I can set locale variable :D
glad you solved.
Local variable is inferred by the url