小编kan*_*nna的帖子

在Rails 3中更改区域设置后,在新域中重定向到同一页面

使用Rails 3.2.8与以下宝石的应用程序

gem 'friendly_id', '~> 4.0'
gem 'route_translator'
Run Code Online (Sandbox Code Playgroud)

在/config/initializers/i18n.rb中

TLD_LOCALES = {
  "com"  => :en,
  "jobs" => :en,
  "net"  => :en,
  "in"   => :en,
  "de"   => :de,
  "ch"   => :de,
  "at"   => :de,
  "br"   => :pt,
  "ar"   => :es,
  "cl"   => :es,
  "mx"   => :es 
}
Run Code Online (Sandbox Code Playgroud)

在/app/controllers/application_controller.rb中,使用before-filter为每个请求设置区域设置:

before_filter :set_auto_locale
def set_auto_locale
  I18n.locale = TLD_LOCALES[request.host.split('.').last]
end
Run Code Online (Sandbox Code Playgroud)

在routes.rb中

localized do
  match "label_vacancies/:view_job"=>"job_seekers#view_job"
  get "label_aboutus", :to => "home#about_us", :as => "about_us"
end
Run Code Online (Sandbox Code Playgroud)

当用户请求更改语言区域设置时,域下方应根据请求的区域设置加载.

在初始化器中

domain_based_on_locale = {
    :en => "xxxxx.com",
    :de => "xxxxx.de", …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails internationalization rails-routing ruby-on-rails-3.2

15
推荐指数
1
解决办法
1215
查看次数

在rails应用程序的前端获取实时日志

在rails 3.x应用程序中,我使用net :: ssh并向远程pc运行一些命令.我想将实时日志显示给用户的browser.like,如果有两个命令在net :: ssh中运行执行即echo "Hello",echo "Bye"被传递,然后"你好"应显示在其execution.Here后立即整理浏览器是我使用了SSH连接,并在轨道上运行的应用程序在Ruby中命令代码

Net::SSH.start( @servers['local'] , @machine_name, :password => @machine_pwd, :timeout => 30) do |ssh|      
  ssh.open_channel do |channel|
    channel.request_pty         
    channel.exec("echo 'ssh started'")                                   
    channel.exec("ruby -v") 
    channel.exec("rails -v") 
    channel.exec("echo 'ssh Finished'") 


    channel.on_close do |ch|
      puts "****shell terminated****"
    end

    channel.on_eof do |ch|
      puts "****remote end is done sending data****"            
    end
    channel.on_extended_data do |ch, type, data|
      puts "****got stderr****: #{data.inspect}"
    end
    channel.on_data do |channel, data|
      puts "****ondata****: #{data} \n"                    
      puts "****channel****: #{channel} \n"          
      $logs << …
Run Code Online (Sandbox Code Playgroud)

ruby ssh ruby-on-rails net-ssh eventmachine

6
推荐指数
1
解决办法
843
查看次数