3

以前にこの質問をして、修正されたと思いましたが、そうではありません。ここに前の質問

私の問題は、入力するときにルートを設定しようとしていることです

localhost:3000 / sites / admin

にリダイレクトする必要があります

localhost:3000 / en / sites / admin

これが私のroutes.rbファイルです

scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
  get "log_out" => "sessions#destroy", as: "log_out"
  get "log_in" => "sessions#new", as: "log_in"

  resources :sites, except: [:new, :edit, :index, :show, :update, :destroy, :create]   do
  collection do
    get :home
    get :about_us
    get :faq
    get :discounts
    get :services
    get :contact_us
    get :admin
    get :posts
  end
end
resources :users
resources :abouts
resources :sessions
resources :coupons
resources :monthly_posts
resources :reviews
resources :categories do
collection { post :sort }
resources :children, :controller => :categories, :only => [:index, :new, :create,   :new_subcategory]
end
resources :products do
  member do
    put :move_up
    put :move_down
  end 
end
resources :faqs do
  collection { post :sort }
end 
root :to => 'sites#home'
match "/savesort" => 'sites#savesort'

end

match '', to: redirect("/#{I18n.default_locale}")
match '*path', to: redirect("/#{I18n.default_locale}/%{path}")

ただし、現時点では、/ en / en / en / en / en / en / en / en / en / en / sites / adminにリダイレクトされます(ブラウザーが文句を言うまでenを追加します)。

/ enを追加し続ける理由はありますか?

編集: 答えは素晴らしいです、ありがとう。ルートルートの診断を手伝ってもらえますか?

root to: redirect("#{/#{I18n.default_locale}") # handles /

私はリダイレクトが次のようなものを探していることを知っています

redirect("www.example.com")

それでこの部分を残します

#{/#{I18n.default_locale}

#{はrubys文字列補間を使用していますよね?{が何をしているのかわかりません。

だから私たちは

/#{I18n.default_locale}

文字列補間を使用し、I18n.default_localeの値を出力するのはどれですか?

うまくいけば、それは理にかなっています、私は本当に助けに感謝します、私はたくさん学んでいます。

編集2:

行を変更しました

root to: redirect("#{/#{I18n.default_locale}") # handles /

root to: redirect("/#{I18n.default_locale}") # handles /

しかし、それが正しいかどうかはわかりません。今、私はエラーが発生しています

uninitialized constant LocaleController

ルートから「locale#root」へのエラーが発生していることはわかっていますが、locale#はスコープから取得されると思いました。

引き続きプレイして、進捗状況をお知らせします。

これが私のルートファイルへの新しいリンクですhttps://gist.github.com/2332198

4

2 に答える 2

10

また会おう、ルーヴォーン。:)

テストレールアプリを作成しましたが、次の最小限の例が機能します。

scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
  resources :sites do
    collection do
      get :admin
    end
  end

  root to: "locale#root" # handles /en/
  match "*path", to: "locale#not_found" # handles /en/fake/path/whatever
end

root to: redirect("/#{I18n.default_locale}") # handles /
match '*path', to: redirect("/#{I18n.default_locale}/%{path}") # handles /not-a-locale/anything
于 2012-04-07T17:25:10.720 に答える