2013-02-26 63 views

回答

0

attr_accessible的變化會更安全(不低於),因爲你是從

一切訪問移動默認和這些的保護

一切由保護默認和這些是可訪問

主要風險是,你會打破所有你r現有的表單...除非您明確地將屬性設置爲可訪問,或者明確設置每個類的每個受保護屬性。


因此,例如,與屬性:id, email, phone number, zip_code and first_name 這兩個會導致現有的相同行爲屬性

# only protect these two attributes, everything else is open season 
# a new attribute will start out accessible by default 
attr_protected :id, :email 

# only these attributes are accessible - everything else is protected 
# a new attribute will start out protected by default 
attr_accessible :first_name, :zip_code, :phone_number 
+0

好了,只是爲了驗證,是一個軌道新手,如果我有以下設置,假設出屬性ID,電子郵件,電話號碼,zip_code和first_name。要改變它:attr_accessible:id,:email會是:attr_protected:phone_number,:zip_code,:first_name是的?沒有?也許? – user1703974 2013-02-27 00:28:52

+0

您是否更改爲attr_protected?我認爲這是相反的方式? – 2013-02-27 03:41:51

+0

這是!對不起,我甚至會迷惑自己。例如,現在,我的代碼是attr_accessible:id,:email。 – user1703974 2013-02-27 15:57:49