現在新版的ruby 2.0的ruby,需要rquire 'yaml'嗎?
====
http://reyesyang.info/articles/10
注意在YAML中,字串不一定要用双引号标示。另外,在缩排中空白字符的数目并不是非常重要,只要相同阶层的元素左侧对齐就可以了(不过不能使用TAB字符)。
haml Sass CoffeeScript IaaS Paas SaaS
IaaS 像主機
Paas 設好環境
SaaS 軟體裝好
http://blog.frost.tw/posts/2014/01/15/getting-started-paas-1
haml 處理html
Sass 處理css
CoffeeScript 處理javascript
Paas 設好環境
SaaS 軟體裝好
http://blog.frost.tw/posts/2014/01/15/getting-started-paas-1
haml 處理html
Sass 處理css
CoffeeScript 處理javascript
ruby sinatra activerecord
如果是用
require "sinatra"
require "active_record"
require 'mysql2'
用底下設定比較快
ActiveRecord::Base.configurations = YAML.load_file('database.yml')
ActiveRecord::Base.establish_connection('production')
用
require "sqlite3"
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'blog.db'
)
注意:database.yml 要像底下,關健字不一樣,就不能用
production:
adapter: mysql2
database:
host: localhost
username:
password:
encoding: utf8
require "sinatra"
require "active_record"
require 'mysql2'
用底下設定比較快
ActiveRecord::Base.configurations = YAML.load_file('database.yml')
ActiveRecord::Base.establish_connection('production')
用
require "sqlite3"
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'blog.db'
)
注意:database.yml 要像底下,關健字不一樣,就不能用
production:
adapter: mysql2
database:
host: localhost
username:
password:
encoding: utf8
ruby php implode
ostr = '{ "data": ['
articles = Article.order("created_at DESC")
ostr = ostr + articles.map{|f| ' ["' + f.title.chomp + '", "' + f.file_url + '"] '}.join(', ')
ostr = ostr + "]}"
map 會把activerecord取出來,設給f
然後組字串,最後加上join
這樣就像implode功能,效果很好~~
articles = Article.order("created_at DESC")
ostr = ostr + articles.map{|f| ' ["' + f.title.chomp + '", "' + f.file_url + '"] '}.join(', ')
ostr = ostr + "]}"
map 會把activerecord取出來,設給f
然後組字串,最後加上join
這樣就像implode功能,效果很好~~
ActiveRecord Migration API
http://blackanger.blog.51cto.com/140924/122472/
Migration API
不設定主鍵
create_table :goods, :id => false do |t|
t.integer :good_id
t.string :good_desc
改變主鍵
create_table :goods, :id => good_id do |t|
t.string :good_desc
end
Migration API
不設定主鍵
create_table :goods, :id => false do |t|
t.integer :good_id
t.string :good_desc
改變主鍵
create_table :goods, :id => good_id do |t|
t.string :good_desc
end
[轉]jQuery file upload maxNumberOfFiles options--無用
http://stackoverflow.com/questions/16723877/jquery-file-upload-maxnumberoffiles-and-getnumberoffiles-options
I believe getNumberOfFiles was only added as an option to a recent version of jquery.fileupload-ui.js (8.2.1).
As an alternative, you can set the option singleFileUploads to false, and in the add callback you can throw errors if more than one file is added.
var maxFiles = 1;
$('#fileupload').fileupload({
singleFileUploads: false,
url: '/uploadUrl'
}).bind('fileuploadadd', function (e, data) {
var fileCount = data.files.length;
if (fileCount > maxFiles) {
alert("The max number of files is "+maxFiles);
return false;
}
});
I believe getNumberOfFiles was only added as an option to a recent version of jquery.fileupload-ui.js (8.2.1).
As an alternative, you can set the option singleFileUploads to false, and in the add callback you can throw errors if more than one file is added.
var maxFiles = 1;
$('#fileupload').fileupload({
singleFileUploads: false,
url: '/uploadUrl'
}).bind('fileuploadadd', function (e, data) {
var fileCount = data.files.length;
if (fileCount > maxFiles) {
alert("The max number of files is "+maxFiles);
return false;
}
});
訂閱:
文章 (Atom)