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:

2014-08-21 · 1 min · 33 words · Me

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功能,效果很好~~

2014-08-21 · 1 min · 36 words · Me

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

2014-08-20 · 1 min · 26 words · Me

[轉]php list

Awesome PHP http://briteming.blogspot.tw/2014/04/awesome-php.html

2014-08-20 · 1 min · 3 words · Me

[轉]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; } });

2014-08-18 · 1 min · 78 words · Me