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

[轉]jquery file upload 改檔名

https://github.com/blueimp/jQuery-File-Upload/issues/622 看連結最下面 Here is some updated code that works with the most recent version as of July 18, 2014. class CustomUploadHandler extends UploadHandler { /* Converts a filename into a randomized file name */ private function _generateRandomFileName($name) { $ext = pathinfo($name, PATHINFO_EXTENSION); return md5(uniqid(rand(), true)).'.'.$ext; } /* Overrides original functionality */ protected function trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range) { $name = parent::trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range); return $this->_generateRandomFileName($name); } } $upload_handler = new CustomUploadHandler();

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