murmur by 沒力小僧 (Manic)

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(4)

murmur by 沒力小僧 (Manic)

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(2)

murmur by 沒力小僧 (Manic)

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(6)

murmur by 沒力小僧 (Manic)

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(8)

這篇文章講的很清楚:attributes= (ActiveRecord::Base) - APIdock

這樣要繞過 attr_protected 的 column 時就不用一個一個手動指定了。

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(17)

1. 使用 Model.increment_counter(counter_name, id):

003:0> User.increment_counter(:hit_counter, 1)
User Update (0.8ms)   UPDATE `users` SET `hit_counter` = COALESCE(`hit_counter`, 0) + 1 WHERE (`id` = 1)

2. 使用 Model.update_counters(id, attribute => ammount)

011:0> User.update_counters(1, :hit_counter => 50)
User Update (0.7ms)   UPDATE `users` SET `hit_counter` = COALESCE(`hit_counter`, 0) + 50 WHERE (`id` = 1)

第1個方法可以單純的做+1動作,第2個方法多了指定要加多少。

另外,Rails 還有一個 instance method: increment,但我其實不建議使用它。因為他不是用 sql 的加法來達成 incrment.

013:0> user = User.first
014:0> user.increment(:hit_counter, 2)
015:0> user.save
User Update (0.2ms)   UPDATE `users` SET `updated_at` = '2009-10-26 04:09:00', `hit_counter` = 163 WHERE `id` = 1

這種方式有可能出現 race condition.

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(16)

這裡主要是講 database 使用 mysql 的狀況。

在 Rails 裡,對於 text 的指定只有一種。

而有時我們需要更大的欄位,比方說 medium text, big text。因為有時候,大一點還是比較好。

這時候在 migration 裡的作法有兩種個方式:

第一種是以指定 limit 大小的方式讓 mysql 自行將欄位設定為 medium text (請注意 "content" ):

  1. class CreateArticles < ActiveRecord::Migration
  2.   def self.up
  3.     create_table :articles do |t|
  4.       t.string    :title
  5.       t.text      :content, :limit => 64.kilobytes + 1
  6.       t.timestamps
  7.     end
  8.   end
  9.  
  10.   def self.down
  11.     drop_table :articles
  12.   end
  13. end
  14.  

第二種是在 self.up 後再 exeucte 自行生成你要的欄位:

  1. class CreateArticles < ActiveRecord::Migration
  2.   def self.up
  3.     create_table :articles do |t|
  4.       t.string    :title
  5.       t.timestamps
  6.     end
  7.     execute "ALTER TABLE articles ADD `content` MEDIUMTEXT NOT NULL AFTER `title`"
  8.   end
  9.  
  10.   def self.down
  11.     drop_table :articles
  12.   end
  13. end

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(11)

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(11)

murmur by 沒力小僧 (Manic)

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(17)

發表時間 碎碎念內容
2009-10-19 10:39:25 發表了新的文章在部落格: [Nico中文字幕組]ジェミニ 雙子座
2009-10-19 15:36:43 傳說中的娘家英文版
2009-10-19 16:48:33 咲-saki- 「新雀記ノドッチゲリオン」(OP+劇場版予告) 這個實在有讚到
2009-10-19 19:07:00 測試新版的加圖片

Posted by Manic at 痞客邦 PIXNET Comments(1) Trackback(0) Hits(16)

雙子座 ジェミニ PV 影片截圖

這首歌的作曲者是 Dixie ,他的作品我們之前也有介紹過,《Just Be Friend.》

《雙子座》則是他的 Nico 出道作。

而對繪師紙飛行機(グライダー)來說,這是他第一個以 Vocaloid 雙子(鏡音鈴,鏡音蓮)為主角的的PV,之後所作的PV作品也都是以雙子為主角。

很可愛!(重點)

也因為這部作品的關係,之後 Dixie 出的個人專輯《Fragments》,就請紙飛行機擔當專輯的視覺設計。

專輯也很棒喔!

接下來就請看鏡音雙子唱雙子吧

 

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(17)

在 Rails 裡對做 CRUD 時,有個方便的實作。

params 表示 form parameters,為 hash 型式 (column => value),這樣子若要把 form 的資料接過來只需要一行。

除了 new 之外,還支援這樣的方式:

方便歸方便,但也衍生了一個問題,那就是使用者的 form 表單裡塞了一些我們不希望被修改的 column 時,這些指令依然會被執行。

比方說帳號欄位,我們通常是不希望被修改的。

於是這時候可以使用 attr_accessible 或 attr_protected 來保護這些欄位

attr_protected :account

這樣在使用 new, attributes=(attributes), update_attributes(attributes) 時,account 欄位會被保護,不被這些 method 改變其值。

而如果我們真的要改變的話,需要自行指定。

以下是 Rails api 給的範例,可以更清楚我在講什麼

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(54)

發表時間 碎碎念內容
2009-10-15 09:14:36 remur from gslin: 森薰繪實況

Posted by Manic at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(26)

20071022_aa3a9b3fec0bf89d07bfkaaRASZYGD8y.jpg

雖然說人體鍊成是不被允許的,不過還是有大量的紳士前仆後繼地想掉突破次元的界線

今天看到一個相當簡單又實用的方法來跟大家分享,不用畫鍊成陣,不需要代價(不過需要花一點小錢跟時間)也不會被反噬,輕輕鬆鬆就能摸到自己的另一半

那麼就來看教學影片吧

 

Tags: 科學 人體鍊成 紳士 三次元 科學

Posted by nico at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(73)

今天考TOEIC一整個爆炸,因此要來補充一下紳士力,找到了這一系列清新健康的運動特輯

請大家注意,這是美少女們坐騎馬機的清新健康的動畫

蒂法

 

小闇

 

春菜

 

蒂法版本五天點閱就突破50萬,真不愧士紳是大國尼碰!

Posted by nico at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(71)