整理一下有关SEO的链接,有必要慢慢学习
Google的SEO指导
http://googlewebmastercentral.blogspot.com/2008/11/googles-seo-starter-guide.html
Google的SEO中文指导
http://www.google.cn/ggblog/googlewebmaster-cn/2008/12/google-seo.html
http://docs.google.com/fileview?id=0B5Utlw5ap2R8MGMyM2I3MjktMGE5Yy00OTMxLTkwZDktZmNkNWFhMjJlZGNj&hl=en&pli=1
中文网站管理员博客
http://googlewebmaster-cn.blogspot.com/
SEO on Rails专门网站
http://www.seoonrails.com/
Rails SEO开始手册
http://web.elctech.com/2008/11/19/rails-seo-starter-guide/
2010年5月12日星期三
关于Rails程序安全性
问题
默热情况下ActiveRecord允许访问者更新所有字段,以及子表字段。
这就让系统中的敏感字段暴露在外。
ActiveRecord里面提供了一下两个函数来声明可以改变的字段。
attr_accessible attr_protected
但是在实际使用中,极为不便,因为
ActiveRecord.new
ActiveRecord.update_attributes
的方法将无法正常使用
当然你可以为每个属性赋值,但这个不是聪明的做法。
问题所在不是出现在ActiveRecord上面。
而是应该在ActiveController上屏蔽一些敏感Parameter
寻找良久,以下这个Plugin应该是一个最为完善的解决方案吧。
据说这个是从Merb里面研究出来的,我想Rails3可能会有直接支持吧。
http://github.com/cjbottaro/param_protected
参看以下链接
http://railspikes.com/2008/9/22/is-your-rails-application-safe-from-mass-assignment
安全检查工具
http://thinkrelevance.com/blog/2008/02/26/tarantula-vs-your-rails-app.html
默热情况下ActiveRecord允许访问者更新所有字段,以及子表字段。
这就让系统中的敏感字段暴露在外。
ActiveRecord里面提供了一下两个函数来声明可以改变的字段。
attr_accessible attr_protected
但是在实际使用中,极为不便,因为
ActiveRecord.new
ActiveRecord.update_attributes
的方法将无法正常使用
当然你可以为每个属性赋值,但这个不是聪明的做法。
问题所在不是出现在ActiveRecord上面。
而是应该在ActiveController上屏蔽一些敏感Parameter
寻找良久,以下这个Plugin应该是一个最为完善的解决方案吧。
据说这个是从Merb里面研究出来的,我想Rails3可能会有直接支持吧。
http://github.com/cjbottaro/param_protected
参看以下链接
http://railspikes.com/2008/9/22/is-your-rails-application-safe-from-mass-assignment
安全检查工具
http://thinkrelevance.com/blog/2008/02/26/tarantula-vs-your-rails-app.html
2010年4月5日星期一
release tool - capistrano
Capistrano 是一个基于Rails开发部署工具。原本是主要为Rails应用使用。现在已经比较通用,不光在Rails应用中可以用。
cd app_dir capify . vi config/deploy.rb set :application, "demo" set :deploy_to, "/path/to/your/app/dir" set :scm, :subversion set :user, "user_for_deploy" # cap deploy # This calls both `update' and `restart' # cap deploy:update # This calls both `update_code' or `symlink' # cap deploy:update_code # get source from repository, and call finalize_update # cap finalize_update # This create 3 symbol links [ public, tmp, log ] # cap deploy:restart # This works by calling the script/process/reaper # 如果不是Rails应用,需要覆盖下面2个方法 namespace :deploy do task :finalize_udpate do end task :restart do end end
2010年3月25日星期四
CentOS 5.1 でRails環境構築 エラー(uninitialized constant MysqlCompat::MysqlRes)
CentOS5.1
Yumでインストール
ruby 1.8.5
gem list
*** LOCAL GEMS ***
actionmailer (2.3.5)
actionpack (2.3.5)
activerecord (2.3.5)
activeresource (2.3.5)
activesupport (2.3.5)
capistrano (2.5.18, 2.5.14)
fastthread (1.0.7)
highline (1.5.2)
mysql (2.8.1)
net-scp (1.0.2)
net-sftp (2.0.4)
net-ssh (2.0.21, 2.0.19)
net-ssh-gateway (1.0.1)
passenger (2.2.11, 2.2.9)
rack (1.1.0, 1.0.1)
rails (2.3.5)
rake (0.8.7)
rubygems-update (1.3.6, 1.3.5)
下記のエラーででる
Status: 500 Internal Server Error
uninitialized constant MysqlCompat::MysqlRes
原因は良く分かりませんが、たぶんCentOSのmysql.develと不整合だと思う。
2.7バージョンでmysqlをインストールすることで解決できる。
sudo gem install mysql --version '= 2.7' -- --with-mysql-lib=/usr/lib/mysql
Yumでインストール
ruby 1.8.5
gem list
*** LOCAL GEMS ***
actionmailer (2.3.5)
actionpack (2.3.5)
activerecord (2.3.5)
activeresource (2.3.5)
activesupport (2.3.5)
capistrano (2.5.18, 2.5.14)
fastthread (1.0.7)
highline (1.5.2)
mysql (2.8.1)
net-scp (1.0.2)
net-sftp (2.0.4)
net-ssh (2.0.21, 2.0.19)
net-ssh-gateway (1.0.1)
passenger (2.2.11, 2.2.9)
rack (1.1.0, 1.0.1)
rails (2.3.5)
rake (0.8.7)
rubygems-update (1.3.6, 1.3.5)
下記のエラーででる
Status: 500 Internal Server Error
uninitialized constant MysqlCompat::MysqlRes
原因は良く分かりませんが、たぶんCentOSのmysql.develと不整合だと思う。
2.7バージョンでmysqlをインストールすることで解決できる。
sudo gem install mysql --version '= 2.7' -- --with-mysql-lib=/usr/lib/mysql
2010年2月22日星期一
Railsエラーメッセージ日本語化(参考)
(省略)
errors:
messages:
inclusion: "は一覧にありません。"
exclusion: "は予約されています。"
invalid: "が不正な値です。"
confirmation: "が一致しません。"
accepted: "を承諾してください。"
empty: "が記入されていません。"
blank: "が記入されていません。"
too_long: "は{{count}}文字以内で記入してください。"
too_short: "は{{count}}文字以上で記入してください。"
wrong_length: "は{{count}}文字で記入してください。"
taken: "はすでに使用されています。"
not_a_number: "は数値で入力してください。"
greater_than: "は{{count}}より大きい値を指定してください。"
greater_than_or_equal_to: "は{{count}}以上の値を指定してください。"
equal_to: "は{{count}}を指定してください。"
less_than: "は{{count}}より小さい値を指定してください。"
less_than_or_equal_to: "は{{count}}以下の値を指定してください。"
odd: "は奇数を指定してください。"
even: "は偶数を指定してください。"
# Append your own errors here or at the model/attributes scope.
models:
# Overrides default messages
attributes:
# Overrides model and default messages.
2009年11月17日星期二
ubuntuでRails環境を設定
sudo apt-get udpate
sudo gem update --system
sudo gem update --no-ri --no-rdoc
sudo gem install rails haml --no-ri --no-rdoc
vim-rails設定
sudo apt-get install vim-rails
vim-rails-setup
sudo gem update --system
sudo gem update --no-ri --no-rdoc
sudo gem install rails haml --no-ri --no-rdoc
vim-rails設定
sudo apt-get install vim-rails
vim-rails-setup
2009年10月23日星期五
Rails本地化
Rails2.3加入了I18n,已经能够很好的支持本地化(Locale)了
主要为
以下是我的一个例子,点这里看效果
实现对 英文,中文,日文 三种语言的支持
RAILS_ROOT/app/controller/application_controller.rb
RAILS_ROOT/config/initializers/i18n.rb
RAILS_ROOT/coonfig/locales/en.yml
RAILS_ROOT/coonfig/locales/zh.yml
RAILS_ROOT/coonfig/locales/ja.yml
application_controller.rb
i18n.rb
en.yml
zh.yml
ja.yml
框架自带的验证出错提示信息可参看这里
主要为
- 对框架返回的信息的本地化
- 对数据库表项目的本地化
- 对页面文字的本地化
以下是我的一个例子,点这里看效果
实现对 英文,中文,日文 三种语言的支持
RAILS_ROOT/app/controller/application_controller.rb
RAILS_ROOT/config/initializers/i18n.rb
RAILS_ROOT/coonfig/locales/en.yml
RAILS_ROOT/coonfig/locales/zh.yml
RAILS_ROOT/coonfig/locales/ja.yml
application_controller.rb
# 为本地化处理加一个过滤器
class ApplicationController < ActionController::Base
before_filter :set_locale
protected
def set_locale
session[:locale] = params[:locale] if params[:locale]
I18n.locale = session[:locale] || I18n.default_locale
end
end
i18n.rb
I18n.default_locale = 'en'
LOCALES_DIRECTORY = "#{RAILS_ROOT}/config/locales/"
LANGUAGES = {
'English' => 'en',
'中文' => 'zh',
'日本語' => 'ja'
}
en.yml
en:
number:
currency:
format:
unit: "¥"
layout:
title: "Xi-yang-yang Wedding Garden"
side:
home: "Home"
faq: "Questions"
news: "News"
contact: "Contact"
cart:
title: "Your Cart"
total: "Total"
checkout: "Checkout"
empty_cart: "Empty Cart"
zh.yml
zh:
number:
currency:
format:
unit: "¥"
precision: 2
separator: "."
delimiter: ","
format: "%u%n"
activerecord:
errors:
# The values :model, :attribute and :value are always available for interpolation
# The value :count is available when applicable. Can be used for pluralization.
messages:
inclusion: "必须是表内的值" #is not included in the list
exclusion: "保留" # is reserved"
invalid: "无效" # "is invalid"
confirmation: "与确认值不一致" # "doesn't match confirmation"
accepted: "必须被接受" # "must be accepted"
empty: "不能为空" # "can't be empty"
blank: "不能为空白" # "can't be blank"
too_long: "超长(最長{{count}})" # "is too long (maximum is {{count}} characters)"
too_short: "超短(最短{{count}})" # "is too short (minimum is {{count}} characters)"
wrong_length: "长度不对(字数必须为{{count}})" # "is the wrong length (should be {{count}} characters)"
taken: "该值已经存在" # "has already been taken"
not_a_number: "不是数字" # "is not a number"
greater_than: "必须大于{{count}}" # "must be greater than {{count}}"
greater_than_or_equal_to: "不得小于{{count}}" # "must be greater than or equal to {{count}}"
equal_to: "必须等于{{count}}" # "must be equal to {{count}}"
less_than: "必须小于{{count}}" # "must be less than {{count}}"
less_than_or_equal_to: "不得大于{{count}}" # "must be less than or equal to {{count}}"
odd: "必须为奇数" # "must be odd"
even: "必须为偶数" # "must be even"
record_invalid: "验证失败: {{errors}}" # "Validation failed: {{errors}}"
template:
header:
one: "1个错误发生导致处理失败" # "1 error prohibited this {{model}} from being saved"
other: "{{count}}个错误发生导致处理失败" # "{{count}} errors prohibited this {{model}} from being saved"
body: "以下的项目出错" # "There were problems with the following fields:"
model:
order: "订购"
attributes:
order:
name: "姓名"
address: "地址"
email: "E-mail"
pay_type: "付款方式"
layout:
title: "喜洋洋婚庆花苑"
side:
home: "主页"
faq: "常见问题"
news: "新信息"
contact: "联系"
cart:
title: "你的购物车"
total: "合计"
checkout: "购买"
empty_cart: "清空购物车"
ja.yml
ja:
number:
currency:
format:
unit: "¥"
precision: 2
separator: "."
delimiter: ","
format: "%u%n"
activerecord:
errors:
# The values :model, :attribute and :value are always available for interpolation
# The value :count is available when applicable. Can be used for pluralization.
messages:
inclusion: "リストには含まれていません" #is not included in the list
exclusion: "保留" # is reserved"
invalid: "無効です" # "is invalid"
confirmation: "一致していません" # "doesn't match confirmation"
accepted: "設定しないとなりません" # "must be accepted"
empty: "空にしてはいけません" # "can't be empty"
blank: "空白にしてはいけません" # "can't be blank"
too_long: "長すぎ(最長{{count}}桁数)" # "is too long (maximum is {{count}} characters)"
too_short: "短すぎ(最短{{count}}桁数)" # "is too short (minimum is {{count}} characters)"
wrong_length: "桁数が不正({{count}}桁数)" # "is the wrong length (should be {{count}} characters)"
taken: "もう設定されていました" # "has already been taken"
not_a_number: "数字ではありません" # "is not a number"
greater_than: "{{count}}より大きくしないといけません" # "must be greater than {{count}}"
greater_than_or_equal_to: "{{count}}以上にしないといけません" # "must be greater than or equal to {{count}}"
equal_to: "{{count}}ではないといけません" # "must be equal to {{count}}"
less_than: "{{count}}より小さくしないといけません" # "must be less than {{count}}"
less_than_or_equal_to: "{{count}}以下にしないといけません" # "must be less than or equal to {{count}}"
odd: "奇数にしないといけません" # "must be odd"
even: "偶数にないといけません" # "must be even"
record_invalid: "検証失敗: {{errors}}" # "Validation failed: {{errors}}"
template:
header:
one: "1個のエラーが発生したため処理が失敗しました" # "1 error prohibited this {{model}} from being saved"
other: "{{count}}個のエラーが発生したため処理が失敗しました" # "{{count}} errors prohibited this {{model}} from being saved"
body: "以下のフィールドにエラーが発生しました" # "There were problems with the following fields:"
model:
order: "注文"
attributes:
order:
name: "名前"
address: "住所"
email: "E-mail"
pay_type: "支払方法"
layout:
title: "喜洋々ウエディングガーデン"
side:
home: "ホーム"
faq: "よくある質問"
news: "ニュース"
contact: "お問い合わせ"
cart:
title: "あなたのカート"
total: "合計"
checkout: "チェックアウト"
empty_cart: "カートをクリア"
框架自带的验证出错提示信息可参看这里
订阅:
博文 (Atom)
