记录: resumehack task system

Database insert the array value problem

we want to create a system mentor assgin the resume to edit, just like a task. I want to create a model that have a user_id column this is a integer type, a resume_id column type is a integer too. and I want to thought the rails collection_check_boxes to create multiple resume_id just like a array name of resume_ids. but this not work the box can remove the resume_id of the user origin. because the user and resume have the associate though the user_id and resume_id . they can them primary_key i guess. this answer is not right . second i try to add_coulmn resume_ids to task model this type is string array is ture default “[]” “answer_postion” there some tip to remenber default value must cover the “” ,and the task model can’t build the relationship beacuse taks model not have the resume_id, the resume table can’t find the task throught the assoicate. and we let the strong params pass the array value add :resume_ids => [] to strong params and now the collection_check_boxes

<%= collection_check_boxes(:mentor_task, :resume_ids, Resume.where(:is_paid => true).where(:is_assign => false), :id, :id, include_hidden: false, checked:Resume.where(:is_paid => true).where(:is_assign => false).first.id ) %>

base the this code block we have some must notice the boxes will be have the hide input and this value is empty. this will be cause the error when we select all the resume throught the resume_ids. will be a empty id not found. we must add include_hidden => false office api tourial html_options: { :include_hidden => false } ,but we dont’t need add html_options . we just follow the order to add we want aims. how to remove the empty string form the array.hash version and any? method can pass the value and insert the database. but i want to select one task all resume_is from the ids. I got the resume_ids is the array in a string They can’t use the where(:id => :resume_ids) to select. must convert array can be work .see the 2 link Resume.where(:id=> JSON.parse(:resume_ids) In the rails 3 we user the find_all_by_id, now use where replace the old. ok everything fine in the development env. but sadly when we deploy the produciton env the pg database we create the new task give me a error the typeerror no implicit conversion the array to string,find the 5 this is a answer I can find add serialize :softwarename, Array to task model. and remove all the JSON.parse. now the error not appeal again. but the array not insert the database. base the 9 we remove the serialize :softwarename, Array and change the columnt.string :resume_ids this will be work on the test production but the real server will be add serialize :softwarename, Array can be work. i don’t why????? perhaps the database confusion beacause i rollback so many time in the development env


1 how to permit an array with strong parameters 2 Rails - How to query by multiple ids(array) 3 ActiveRecord.find(array_of_ids), preserving order 4 Rails Get Multiple by ID (useful) 5 production env pg type_error of the array insert 6 Storing arrays in database : JSON vs. serialized array 7 A Rule of Thumb for Strong Parameters 8 Permit Array in Rails Strong Parameters 9 nil is inserted when trying to storing array data with PostgreSQL