【发布时间】:2012-04-04 21:29:43
【问题描述】:
我正在关注 Ryan Bates railscasts I18n Internationalization 并遇到问题。
我正在尝试在链接中设置语言,如下所示:
http://localhost:3000/en/site/services 英语
和
http://localhost:3000/es/site/services 西班牙语
我在我的路由文件中定义这个:
routes.rb
scope ":locale" do
get "site/home"
get "site/about_us"
get "site/faq"
get "site/discounts"
get "site/services"
get "site/contact_us"
get "site/admin"
get "site/posts"
get "categories/new_subcategory"
get "categories/edit_subcategory"
end
我的应用程序控制器中有
before_filter :set_locale
private
def set_locale
I18n.locale = params[:locale] if params[:locale].present?
end
def default_url_options(options = {})
{locale: I18n.locale}
end
在我看来/layouts/application.html.erb
<%= link_to_unless_current "English", locale: "en" %> |
<%= link_to_unless_current "Spanish", locale: "es" %>
现在,每当我尝试运行 rake 路由或导航到我得到的 URL 时
C:\www\project>rake routes
rake aborted!
missing :controller
我对路线还很陌生,有人可以帮我看看/解释这个问题吗? 提前致谢。
【问题讨论】:
标签: ruby-on-rails internationalization rails-routing