来自: http://www.beyondrails.com/blogs/11
ActionMailer现在的实现只支持smtp和Sendmail两种方式发送邮件,配置分别如下:
# ActionMailer::Base.delivery_method = :smtp
# ActionMailer::Base.smtp_settings = SMTP_SETTINGS
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.sendmail_settings = SENDMAIL_SETTINGS
SMTP ...
1,安装ExceptionNotification
ruby script\plugin install http://dev.rubyonrails.org/svn/rails/plugins/exception_notification/
光安装这个插件是不能利用gmail发送邮件的,因为gmail需要https,所以还需要安装一个插件
2,安装action_mailer_tls
ruby script/plugin install http://svn.nanorails.com/plugins/action_mailer_tls
3,修改exception_no ...
CodeRay是一个语法高亮的Ruby库,效率很不错。
CodeRay目前支持的语法包括:
Ruby
C
Delphi
HTML
RHTML (Rails)
Nitro-XHTML
YAML
SQL
Python
Perl
PHP
Java
railscasts的播主Ryan Bates自定义了一些css,让ruby、rhtml等代码看起来非常cool!
1,安装coderay gem
gem install coderay
2,在application.rb中
require 'coderay'
3,在application_helper.rb里添加一个helpe ...
1,客户端机器安装Capistrano
gem install -y capistrano
2,应用到项目
cd D:\projects\beyondrails
capify .
3,修改config\deploy.rb
DEPLOY_PATH = "/var/www/vhosts/hideto/html/www.beyondrails.com"
set :application, "beyondrails"
set :repository, "https://beyondrails.googlecode.com/svn/trunk/beyondrails"
...
使用lighttpd+fcgi跑Rails程序,文件上传会silently failed,任何报错都没有
http://trac.lighttpd.net/trac/ticket/338
我研究了一下午,未果。
大家有没有解决方法?
有什么样的需求就有什么样的对策
当vhost上的帐号没有gem install权限时,我们可以利用ruby、rails灵活多变的特性,将gem改为Rails插件来用
首先本地安装gem,然后按照plugin目录结构创建init.rb和lib文件夹,然后将本地gem目录里的lib文件夹里的rb文件copy到plugin的lib文件夹,然后修改init.rb,require位于plugin下的lib文件夹里的主文件,ok!
1,去http://recaptcha.net/sign up,获得pub key和priv key
2,安装recaptcha gem
gem install --source http://www.loonsoft.com/recaptcha/pkg/ recaptcha
3,在environment.rb里设置key
require 'recaptcha'
RCC_PUB = 'pub key'
RCC_PRIV = 'priv key'
4,修改application.rb
class ApplicationController < ActionContr ...
文件上传很慢时,UI没有什么用户提示,这样让人很费解,所以我们可以给文件上传添加一个动态而美观的progress_bar
首先给form_for添加一个onsubmit事件,并在form_for下紧跟一个显示progress_bar的div:
<% form_for(:asset, :url => assets_path, :html => { :multipart => true, :onsubmit => "show_progress_bar(this);" }) do |f| %>
<p>
<b>上传文件</b><br />
...
上传文件的size经常结果为0,让人很费解
解决办法,attachment_fu.rb:
# about line 300
def uploaded_data=(file_data)
return nil if file_data.nil? || file_data.size == 0
self.content_type = file_data.content_type
self.filename = file_data.original_filename if respond_to?(:filename)
if file_data.is_a?(Strin ...
再谈ActiveRecord、MySQL和transaction
第一篇:ActiveRecord如何与MySQL交互
我们自定义的MyModel继承于ActiveRecord::Base类
MyModel < ActiveRecord::Base
MyModel.find_xxx -> find_by_sql -> connection.select_all(sql)
MyModel.create_xxx -> connection.insert(sql)
MyModel.update_xxx -> connection.update(sql)
MyMode ...
原文: Building a Social Network Site in Rails
本文不会手把手教你如何实现一个社会化网络站点,而是覆盖一些你可能认为有用的插件和事情。
社会化网络插件
Restful Authentication
RESTful Authentication可能是Rails里的用户认证标准,它让你轻松搭建用户注册、登录和email通知等功能。
它没有实现忘掉密码的功能,但是有一个很好的教程指南。
# To Install
ruby script/plugin source http://svn.techno-weenie.net/projects/plugi ...
翻阅本书的读者,相信您对Ruby on Rails并不陌生。Ruby on Rails的创造者DHH曾被2005年“全球开源大会”(OSCON)评为“年度最佳黑客”,《连线》杂志封面人物更将其标榜为“地球上最炙手可热的黑客”。而他与Dave Thomas合著的另一部著作——《Agile Web Development with Rails》一书曾在2006年获得享有软件开发界奥斯卡之誉的Jolt Awards(震撼大奖)。一时间,Ruby on Rails大红大紫、风光无限,大大小小的Rails门户、Rails博客、Rails播客如雨后春笋般纷纷涌现,Web开发貌似迎来了革命性的救世主,国内外 ...
will_paginate插件很好用,但是在Rails的development模式下查看SQL日志时发现这样的现象:
使用paginate_by_sql方法来search数据时生成这样的两条SQL语句:
SELECT COUNT(*) FROM(select a.* from table_a where ... order by id asc) AS count_table
select a.* from table_a where ... order by id asc
这样的SELECT COUNT语句的性能就很有问题了。
查看will_paginate的实现-》finder ...
Rails有乐观锁悲观锁,但是悲观锁它不支持整个table的锁啊
好吧,那就SQL吧:
ActiveRecord::Base.connection.execute("LOCK TABLE XXX WRITE")
ActiveRecord::Base.connection.execute("UNLOCK TABLES")
在Console下试了试,不同进程,可以锁!同步了!
但是,在fastCGI下就是锁不住!
搞一个全局变量,很可行!
ActiveRecord::Base.connection.execute("select get_lock('lock_xxx', 100)" ...
cron job如果加载rails环境来使用Logger,这样就有多个进程操作Logger,在Logger做Shifting时会有异常,比较取巧的解决方法就是在environment.rb里加一个常量判断(sliu大人的建议):
if !$CRON_JOB_STATUS
$LOG = Logger.new(File.join(RAILS_ROOT, '/log/rails.log'),'daily')
else
$LOG = Logger.new(File.join(RAILS_ROOT, '/log/cronjob.log'),'daily')
end
然后在cron ...
加入/usr/bin/ruby和/usr/local/bin/ruby有两份程序,而你又没有指定执行哪个,而是按PATH先后顺序来执行,这样就很容易出一些乱七八糟的问题:
no such file to load -- rubygems
no such file to load -- json
no such file to load -- ubygems
所以最好是在你的Cron Job里这样做:
/usr/local/bin/ruby xxx_job.rb
http://webonrails.com/2007/09/13/acts_as_solr-starting-solr-server-on-windows/
acts_as_searchable是一个Rails插件,它依赖于Hyper Estraier这个独立的搜索引擎所提供的索引和搜索服务
1,安装Hyper Estraier
去http://hyperestraier.sourceforge.net/win/下载Binary Packages for Windows,将hyperestraier-1.4.10-win32.zip解压到C:\hyperestraier,将C:\hyperestraier加入到系统环境变量PATH中去
2,启动Hyper Estraier
C:\est> estmaster init .
C:\est> ...
sphinx-0.9.8-rc1-win32与MySQL5.1.x一起使用会出错,换成低版本的MySQL5.0.x即可
应该是MySQL的client/server libraries不匹配导致的
gem install ferret -v=0.11.5 --platform mswin32
要加0.11.5版本号和mswin32平台两个参数,否则安装出错
其实很简单,加载environment.rb文件即可,如假设一个.rb脚本在Rails项目根目录下:
require File.dirname(__FILE__) + '/config/environment'
然后就可以使用ActiveRecord模型了
忘了是在哪个家伙的Blog上copy了一段代码:
config.logger = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log.#{Date.today.to_s}", "daily")
貌似看起来很对,但是结果是出现了production.2008-02-28.20080228这种东西
几经周折,才发现对Rails的log的rotate原理没搞清楚
Rails的log的rotate是在一天的凌晨时间对前一天的.log文件重命名加上日期后缀,然后创建一个新的.log文件,新创建的.log文件不带日期后缀。
所以.#{Date.today. ...
acts_as_sphinx.rb第14行:
default_options = {:host => 'localhost', :port => 3312, :index => name.tableize}
这里查询的index名字直接用了name.tableize,没有考虑使用set_table_name来设置一些遗留数据库表的情况,所以应该改为:
default_options = {:host => 'localhost', :port => 3312, :index => table_name || name.tableize}
使用Mocha时,发现Model的find方法的返回值变成true了
几经折腾,发现是rspec_matchers这个plugin的一段代码导致的:
def validate_uniqueness_of(attribute)
return simple_matcher("model to validate the uniqueness of #{attribute}") do |model|
model.class.stub!(:find).and_return(true)
!model.valid? && model.errors.invalid?(attrib ...
Rspec
Mocha
集成方法就是在spec_helper.rb里配置一下:
config.mock_with :mocha
这样就可以在Rspec测试中使用Mocha了
# javascripts_controller.rb
caches_page :dynamic_states
# config/environments/development.rb
config.action_controller.perform_caching = true
# config/environment.rb
config.load_paths << "#{RAILS_ROOT}/app/sweepers"
# app/sweepers/state_sweeper.rb
class StateSweeper < ActionCo ...
javascripts_controller.rb
def dynamic_states
@states = State.find(:all)
end
application_helper.rb
def javascript(*files)
content_for(:head) { javascript_include_tag(*files) }
end
def stylesheet(*files)
content_for(:head) { stylesheet_link_tag(*files) }
end
people/new.html.er ...
看看Rails2.0生成RSS feeds有多简单:
routes.rb:
map.resources :articles
app/controllers/articles_controller.rb:
def index
@articles = Article.find(:all)
end
app/views/index.html.erb:
<%= link_to "RSS Feed", formatted_articles_url(:rss) %>
app/views/index.rss.builder:
xml.instruct! :xml ...
我们可能会经常使用logger.debug来debug一些变量
logger.debug "Year: #{year} Month #{month}"
麻烦,不是么,我们可以添加一个config/initializers/logger_additions.rb
logger = ActiveRecord::Base.logger
def logger.debug_variables(bind)
vars = eval('local_variables + instance_variables', bind) # 得到所有本地变量和实例变量
vars.each do ...
我们的程序中可能有一些参数配置,我们可以将这些配置放在外部YAML文件里而不必污染应用程序代码:
# config/initializers/load_config.rb
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV]
# application.rb
def authenticate
if APP_CONFIG['perform_authentication']
authenticate_or_request_with_http_basic do |usernam ...
- 浏览: 612374 次
- 性别:

- 来自: BJ

- 详细资料
搜索本博客
我的相册
screenshot
共 1 张
共 1 张
最近加入圈子
最新评论
-
深入了解Java ClassLoader ...
当我对字节码编译不知所措的时候,发现了这个帖子 谢谢楼主,目前正在学习ASM C ...
-- by ytzhsh -
Rails里如何结合Exceptio ...
收藏了,小工具,好东西.
-- by yangzhihuan -
使用coderay和railscasts ...
不错,很爽,如果能显示成textmate那样的就好了。
-- by carlosbdw -
Axis2快速上手指南
看得很累,希望楼主写个HelloWorld.谢谢
-- by zznj1123 -
使用coderay和railscasts ...
javaeye自己用的是什么highlight什么的吗?
-- by qichunren






评论排行榜