我有一个网址
<li><%= link_to "#{t('feed.add')}", feed_path(locale) %></li>
问题是,在注册后,当我第一次按下此链接时,它会将我重定向到mydomain.com/feed
并打印下一个错误:
"feed" is not a valid locale
中的
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
但当我返回并再次点击时,它会将我重定向到:
mydomain.com/en/feed
那么,这个奇怪问题的问题是什么?
更新
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
match '', :via => [:get], to: redirect("/#{I18n.locale}")
get '/en/youarethechampion' => "winners#winner"
get "/en/hook" => "feed#hook"
get '/thisvideonotfound' => 'feed#notFound'
get '/:locale/feed', to: 'feed#index', as: 'feed'
post '/:locale/feed/create', to: "feed#create"
get '/:locale/feed/new', to: "feed#new", as: 'feed_new'
get '/:locale/feed/destroy', to: "feed#destroy", as: 'feed_destroy'
get '/:locale/feed/edit', to: "feed#edit", as: 'feed_edit'
get '/:locale/feed/update', to: "feed#update", as: 'feed_update'
scope :path => "(:locale)", :locale => /en|ru/ do
devise_for :users
end
match '/:locale/posts/search/', to: 'home#search', as: 'search', via: :get
get '/:locale/page/:page_slug' => 'home#about'
get '/:locale/:category/:id/', to: 'home#show', as: 'feed_show'
get '/:locale/:id/', except: 'search', to: 'home#by_category', as: 'category'
get '/:locale/posts/user/:name/', to: 'home#by_user', as: 'user'
get '/:locale/posts/tag/:tag/', to: 'home#by_tag', as: 'tag'
get '/:locale/pages/:page/', to: 'page#show', as: 'page'
post '/feed/:id/comments/', to: 'home#create_comment'
get '/:locale/', to: "home#index"
答案 0 :(得分:0)
好的,在注册后看起来像是场景:locale是nil
,而这一行
<li><%= link_to "#{t('feed.add')}", feed_path(locale) %></li>
链接到/feed
。 (尝试将其打印在链接前面)
<li>
Locale is <%= locale %>
<%= link_to "#{t('feed.add')}", feed_path(locale) %>
</li>
然后路线认为/ feed属于这条路线
get '/:locale/', to: "home#index"
并尝试将feed
设置为区域设置。它不起作用!然后你移动到你定义的另一个页面&#34; real&#34; local到default_locale - &gt;烯。
I18n.locale = params[:locale] || I18n.default_locale