2014-03-13 104 views
0

我有多種屬性我想堅持的,併爲他們在PARAMS中存在的話是這樣的:傳遞一個散列強PARAMS

Parameters: 
{"utf8"=>"✓", "authenticity_token"=>"5hUuVqqmPulYVPsCP6GF4Tya3QWpDQXBQJVckbDPxRA=", 
"program"=>{"name"=>"Save categories", "description"=>"", 
"category_ids"=>{"0"=>"53029921d2b38bf8da000015", "1"=>"", "2"=>""}, "eligibility"=>"", 
"how_to_access"=>"", "street_address"=>"", "city"=>"", "state"=>"", "zip"=>"", 
"neighborhood_ids"=>["", "52dda579d2b38bf39d000025", "52dda579d2b38bf39d00002e"], 
"county"=>"", "phone"=>"", "email"=>"", "website"=>""}, "commit"=>"Update Program", 
"id"=>"5320c2dbd2b38b90d7000004"} 

具體來說,除了category_ids一切的工作哈希:

"category_ids"=>{"0"=>"53029921d2b38bf8da000015", "1"=>"", "2"=>""} 

在我利用這些類別來創建和更新各種控制器,這是我強烈參數

def program_params 
    params.require(:program).permit(:name, :slug, :description, :cost, :min_age, :max_age, :how_to_access, :min_grade, 
           :max_grade, :start_date, :end_date, :notes, :tag_list, :eligibility, 
           :street_address, :state, :city, :zip, :county, :phone, :email, :website, neighborhood_ids: [], category_ids: []) 
end 

具體而言,我不知道這部分應該如何寫:

category_ids: [] 

我會嘗試不同的東西,直到我弄清楚如何堅​​持它。事實上,我會通過這些參數,沒有得到保存,所以我想我需要明確說明[:0,:1,:2],但我不確定如何去做,或者這是正確的解決方案

編輯:

新PARAMS這個樣子

"category_ids"=>{"one"=>"53029921d2b38bf8da000006", "two"=>"53029921d2b38bf8da00001b", "three"=>"53029921d2b38bf8da000004"} 

形式的實際HTML被消磨了我這裏。解決了!

回答

2

params.require(:program).permit(:name, :slug, :description, :cost, :min_age, :max_age, :how_to_access, :min_grade, :max_grade, :start_date, :end_date, :notes, :tag_list, :eligibility, :street_address, :state, :city, :zip, :county, :phone, :email, :website, neighborhood_ids: [], category_ids: ['1','2', '3'])

不能轉換成第一個符號。

+0

我一直在想這件事。謝謝...我會改變一切 – dislikesAppleCores

+0

:)你有奇怪的用戶名;) –