使用ROR組建系統時的一些注意點(持續追加中)

2021-04-16 16:35:09 字數 976 閱讀 6424

想使用ruby on rails開發乙個小系統,因為才剛接觸,難免會到處碰壁。在這裡先做乙個筆記。

a.寫登陸頁面時可能會用到以下類似的**。

class

user 

<

activerecord::base

defself.authenticate(si_user)

@userid 

=si_user.userid

@password 

=si_user.password

user 

=find(:first, :conditions 

=>["

userid = ? and password = ?

", @userid, @password])

return

user

end  

end注意:如果查詢語句寫成:

user = find(:first, ["userid = ? and password = ?", @userid, @password])

則後面的查詢條件會被忽略。

b.關於rails的頁面標籤:

譬如這樣的**:<%= text_field 'user', 'userid', :style => 'width:160px' %>,執行後會被解釋成:

因為text的name被解析成了user[userid],後台的取值辦法:params[:user][:userid]

注意:params[:user[userid]]==>這樣寫是錯誤的。(因為如果name="user_userid"的話正確的取值寫法是params[:user_userid],所以很容易出現這樣的錯誤)

收藏一些RoR的外掛程式

檔案上傳 filecolumn 網頁 安裝 主題支援 theme support 安裝 動態的樹型結構 livetree 網頁 國際化外掛程式 globalize 網頁 安裝 本地化 localization 網頁 安裝 檔案上傳進度顯示 rails upload progress 網頁 demo ...

Java使用Thread時的一些注意點

新建執行緒很簡單,只要使用new關鍵字建立乙個執行緒物件,並且將它start 起來即可 thread t1 new thread t1.start 注意 下面的 也能通過編譯和正常執行,但是卻沒有新建乙個執行緒 thread t2 new thread t2.run 這只是簡單的普通方法呼叫,所以沒...

使用malloc和free時的一些注意事項

在c中,動態記憶體是乙個讓人又愛又恨的,這裡對malloc和free的使用進行一定的小介紹。一般而言,先通過malloc 或calloc等函式 分配動態記憶體,然後通過free來進行記憶體的釋放。但有時會出現free失敗的情況。如下列程式 include include include int ma...