分类目录归档:Ruby

Ruby

Encoding::UndefinedConversionError

arr=line.force_encoding("utf-8").split("\t")

出现:`encode’: “\xAF\xD0” from GBK to UTF-8 (Encoding::UndefinedConversionError)

更改为以下
arr= line.encode('UTF-8',{
:invalid => :replace,
:undef   => :replace,
:replace => '?'
}).split("\t")

Ruby 发送邮件

SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式。

Ruby提供了 Net::SMTP 来发送邮件,并提供了两个方法 new 和 start:

new 方法有两个参数:

  • server name 默认为 localhost
  • port number 默认为 25

start 方法有以下参数:

  • server – SMTP 服务器 IP, 默认为 localhost
  • port – 端口号,默认为 25
  • domain – 邮件发送者域名,默认为 ENV[“HOSTNAME”]
  • account – 用户名,默认为 nil
  • password – 用户密码,默认为nil
  • authtype – 验证类型,默认为 cram_md5

SMTP 对象实例化方法调用了 sendmail, 参数如下:

  • source – 一个字符串或数组或每个迭代器在任一时间中返回的任何东西。
  • sender -一个字符串,出现在 email 的表单字段。
  • recipients – 一个字符串或字符串数组,表示收件人的地址。

继续阅读

How to install mod_ruby and eruby on Linux server

mod_ruby embeds the Ruby interpreter into the Apache web server, allowing Ruby CGI scripts to be executed natively. These scripts will start up much faster than without mod_ruby.

1. Install eRuby & mod_ruby1) Install eRuby:

# wget http://www.modruby.net/archive/eruby-1.0.5.tar.gz
# tar -xzvf eruby-1.0.5.tar.gz
# cd eruby-1.0.5/
# ./configure.rb –with-charset=euc-jp –enable-shared
# make; make install

2) Install mod_ruby

i)Download latest mod_ruby tar file
# wget http://www.modruby.net/archive/mod_ruby-1.2.6.tar.gz
# tar -xzvf mod_ruby-1.2.6.tar.gz
# cd mod_ruby-1.2.6/
#  ./configure.rb –enable-eruby –with-apxs=/usr/local/apache/bin/apxs
# make; make install

继续阅读

Ruby 1.9.3 by Software Collections

A recent stable release of Ruby with Rails 3.2.8 and a large collection of Ruby gems. This Software Collection gives developers on Red Hat Enterprise Linux 6 access to Ruby 1.9, which provides a number of new features and enhancements, including improved Unicode support, enhanced threading, and faster load times. 继续阅读