Google自訂搜尋

剛剛跟老婆玩完熱舞Online,感覺還蠻不錯的
比較喜歡玩情侶模式>///<

跟自己心靈相通的人一起玩遊戲的感覺真的很不錯!

底下照片是跳得比較好後的結果>///<


hechian 發表在 痞客邦 留言(2) 人氣()

Rails中有個安全性漏洞,請參考

* http://manuals.rubyonrails.com/read/chapter/47
* http://www.javaeye.com/topic/58686

假設我們有個users table,表格欄位如下:

* username # 很明顯就是帳號
* password # 這就是密碼
* role     # 權限名稱

而我們提供給使用者註冊的頁面只會有username跟password欄位

<%= form_tag :action => "signup" %>
  <%= text_field "user", "username" %>
  <%= password_field "user", "password" %>
</form>

會產生以下HTML↓

<form action="http://www.xxx.com/user/signup">
  <input type="text" name="user[username]" />
  <input type="password" name="user[password]" />
</form>

這時,一個使用者如果自己寫出一個表單:

<form action="http://www.xxx.com/user/signup">
  <input type="text" name="user[username]" />
  <input type="password" name="user[password]" />
  <input type="hidden" name="user[role]" value="admin" />
</form>

然後你的後端如果是這樣:

User.create(params[:user])

哦.. 這就真的好玩了..
使用者在註冊時直接提權..
那這要怎樣處理呢?

我們可以在
app/model/user.rb
內新增這行:

  attr_protected :role

這樣一來,該欄位就會確定被忽略掉而不會被新增..
不過你得做一下這道手續:

user = User.new(params[:user])
user.role = sanitize_properly(params[:user][:role])

===== 分 - 隔 - 線 =====

另外,我們可以使用

  attr_accessible :username, :password

這有點類似白名單的方式,可以過濾掉沒出現的欄位...


hechian 發表在 痞客邦 留言(0) 人氣()

有個網站專門在做問卷調查的
會員在做完問卷後系統會給點數或者是抽獎卷
點數最少是五點,不過那是不符合問卷調查對象時才給五點
最多我拿到一千多點=_=a
抽獎卷的獎品價值最低也超過一千台幣!
按下這個網址就可以申請了:
請按我申請


hechian 發表在 痞客邦 留言(0) 人氣()

1. Rails Jobs in Taiwan
2. QA for UbiSunrise
3. ActionMailer for Abon
4. My case
5. Projects

hmm... 三月還真忙阿=_=..
據說Thegiive手上有Rails jobs相關的東西.. 改天來問問好了:P

just a memo this.


hechian 發表在 痞客邦 留言(0) 人氣()

用過Flickr嗎?
如果你有Flickr相簿,應該對於修改照片標題、說明的方式記憶猶新吧?
那種就叫做 In Place Editing
在Rails中,要實做這種技術並不難,因為本身就內建這個功能
不過到了Rails 2.0將會把這個從內建移除變成Plugins形勢存在
可以參考這篇:In-plcae-editing by Rails
不過我在這裡重新說明一次使用方式
如果有<%= javascript_include_tag :defaults %>的話,那只剩下兩個步驟:

Controller:
  class ObjectController < ApplicationController
    in_place_edit_for :object, :method
  end

View:
  <%= in_place_editor_field :object, :method %>
這樣就可以建立起最基本的InPlaceEditing欄位
可是最基本的都是英文,因此Rails也提供了修改參數,可以參考 這篇
in_place_editor_field欄位有四個參數:
  in_place_editor_field(object, method, tag_options = {}, in_place_editor_options = {})
而修改的部分則是放在第四個參數;假設我要修改:saving_text:
  <%= in_place_editor_field(:object, :method, {}, {:saving_text => "儲存中..."} %>
改好後記得重新整理頁面!

另外,如果要建立多個欄位的話,必須用這種方法:

  class ObjectController < ApplicationController
    in_place_edit_for :object, :method1
    in_place_edit_for :object, :method2
    in_place_edit_for :object, :method3
  end

這樣寫超麻煩的!因此可以這樣:
  class ObjectController < ApplicationController
    %w"method1 method2 method3".each do |m|
      in_place_edit_for :object, m.to_sym
    end
end

這樣未來在新增刪除上都會很方便!


hechian 發表在 痞客邦 留言(0) 人氣()

剛在跟朋友聊天,講到removeEventListener跟detachEvent
後來在感嘆.. 英文真的很奧妙

append(add) -> remove
create -> delete(destroy)
attach -> detach

嗯.. 意思好像差不多
為什麼要分呢=  ="


hechian 發表在 痞客邦 留言(0) 人氣()