国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

ruby on rails 代碼技巧

2019-10-26 19:22:26
字體:
供稿:網(wǎng)友

git倉庫輸出
git archive --format=tar --prefix=actasfavor/ HEAD | (cd /home/holin/work/ && tar xf -)
輸出到/home/holin/work/actasfavor/目錄下

Posted by holin At May 16, 2008 16:42
加載plugins中的controller和model

# Include hook code here
require 'act_as_favor'
# make plugin controller, model, helper available to app
config.load_paths += %W(#{ActAsFavor::PLUGIN_CONTROLLER_PATH} #{ActAsFavor::PLUGIN_HELPER_PATH} #{ActAsFavor::PLUGIN_MODELS_PATH})
Rails::Initializer.run(:set_load_path, config)
# require the controller
require 'favors_controller'
# require models
require 'favor'

Posted by holin At May 15, 2008 15:36
使用最頻繁的前5個(gè)命令
history | awk {'print $2'} | sort | uniq -c | sort -k1 -rn| head -n5

Posted by holin At May 15, 2008 10:40
按數(shù)組元素的某屬性排序
@users.sort!{|a, b| a.last <=> b.last }

Posted by holin At May 11, 2008 14:35
按日期備份數(shù)據(jù)庫
mysqldump db_name -uroot > "/root/db_backup/kaoshi_web_`date +"%Y-%m-%d"`.sql"

Posted by holin At May 08, 2008 12:05
用memcached手動cache數(shù)據(jù)

sql = "SELECT * FROM blogs LIMIT 100"
Blog.class
k = MD5.new(sql)
@blogs = Cache.get k
if @blogs.blank?
@blogs = Blog.find_by_sql(sql)
Cache.put k, @blogs, 60*30 #expire after 30min
end
memcache-client 1.5.0:
get(key, expiry = 0)
put(key, value, expiry = 0)

Posted by devon At May 04, 2008 20:39
shuffle an array

class Array
def shuffle
sort_by { rand }
end
def shuffle!
self.replace shuffle
end
end

Posted by holin At May 04, 2008 15:39
讓所有的ajax請求都不render :layout

def render(*args)
args.first[:layout] = false if request.xhr? and args.first[:layout].nil?
super
end

Posted by devon At May 03, 2008 10:53
Find with Hash

Event.find(
:all,
:conditions => [ "title like :search or description like :search",
{:search => "%Tiki%"}]
)

Posted by devon At May 03, 2008 10:49
執(zhí)行sql語句腳本

mysql -uroot -p123<<END
use dbame;
delete from results;
delete from examings;
quit
END

Posted by holin At May 01, 2008 12:14
SQL Transaction in Rails

def fetch_value
sql = ActiveRecord::Base.connection();
sql.execute "SET autocommit=0";
sql.begin_db_transaction
id, value =
sql.execute("SELECT id, value FROM sometable WHERE used=0 LIMIT 1 FOR UPDATE").fetch_row;
sql.update "UPDATE sometable SET used=1 WHERE id=#{id}";
sql.commit_db_transaction
value;
end

Posted by holin At April 30, 2008 09:37
顯示 Flash 消息的動態(tài)效果

<% if flash[:warning] or flash[:notice] %>
<div id="notice" <% if flash[:warning] %>class="warning"<% end %>>
<%= flash[:warning] || flash[:notice] %>
</div>
<script type="text/javascript">
setTimeout("new Effect.Fade('notice');", 15000)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 嘉善县| 乳山市| 宁陕县| 武穴市| 汝州市| 深水埗区| 宜兰市| 象山县| 平原县| 金门县| 麻江县| 水城县| 惠东县| 措美县| 津南区| 扎囊县| 汤原县| 溧阳市| 治多县| 京山县| 华亭县| 浠水县| 海丰县| 习水县| 苗栗县| 库车县| 栾城县| 西乌珠穆沁旗| 夏邑县| 宁乡县| 蕉岭县| 新邵县| 洮南市| 兰坪| 宁强县| 潍坊市| 兴文县| 龙胜| 精河县| 凉城县| 海林市|