This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless Rails.env.production? | |
connection = ActiveRecord::Base.connection | |
connection.tables.each do |table| | |
connection.execute("TRUNCATE #{table}") unless table == "schema_migrations" | |
end | |
sql = File.read('db/import.sql') | |
statements = sql.split(/;$/) | |
statements.pop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
controllers = Dir.new("#{Rails.root}/app/controllers/admin").entries | |
controllers.each do |controller| | |
if controller =~ /_controller/ | |
cont = controller.camelize.gsub(".rb","") | |
cont1 = controller.gsub("_controller.rb", "") | |
(eval("Admin::#{cont}.action_methods")).sort.each {|met| | |
puts "admin/#{cont1}##{met}" | |
} | |
end | |
end |
As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.
All the complexity is handled by ActiveRecord::Transactions
. Any model class or instance has a method named .transaction
. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the | |
# CREATE block and create them in separate commands _after_ all the INSERTs. | |
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk. | |
# The mysqldump file is traversed only once. | |
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite | |
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Mac fix 1 - Install the Nokogiri gem on Mac OS 10.9 Mavericks | |
# | |
# Usage: to configure and install using Bundler, pass in 'bundle' as an argument to the script. | |
# | |
# Nokogiri works at a very low level, so it has many issues on various platforms. | |
# As a result, the command `install gem nokogiri` often will fail. This fix is for | |
# errors involving 'libiconv', such as the following one I encountered: | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div><br></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b> "newsletter";<[email protected]>;</div><div><b>发送时间:</b> 2013年9月17日(星期二) 中午12:13</div><div><b>收件人:</b> "yuyou"<[email protected]>; <wbr></div><div></div><div><b>主题:</b> Tower每月消息(2013年09月17日)</div></div><div><br></div> | |
<div style="background:#EDEDED url('http://towerfiles.oss.aliyuncs.com/newsletter_static/header_bg_01-0913.jpg') 50% 12px no-repeat; min-width:700px; padding:50px 30px 30px; margin:0; font-size:16px; line-height:1.6;"> | |
<div class="twr-newsletter-content" style=" | |
background:#fff; | |
border:1px solid #ccc; | |
border-top:0; | |
max-width:700px; min-width:700px; | |
margin:0 auto; | |
padding:0 | |
"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Received: from mail19.sendcloud.org (unknown [101.227.180.11]) | |
by newmx103.qq.com (NewMx) with SMTP id | |
for <[email protected]>; Fri, 21 Nov 2014 14:12:14 +0800 | |
X-QQ-FEAT: I0VBZjNhVPoB2VizW1VKNfwzEHh/wk1Ayezm8NFRuYe/CY1W8gkg4x8s+i55b | |
nocWIabTicaMC693fjWaHJsjx2PhOWvPVl+qqsxSYkN+3exA5S02EGDh8LQkP+y/Zcexwm4 | |
kxbzFLCau0QyJCXXYsSJ4cNQ7sZW/CT3ojqQPwJseVbn+C0YPiPJ3EnTxLGtTo6RM/IeUnb | |
7E/yZpXNCf7WDmysWeYq1P0JU7Bnz9zA= | |
X-QQ-MAILINFO: MjJD59SVx+LnP5qnRvn6Mb+6nxfomRRgidftc9HxYO7Httn7xWurqKbpO |