Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Moving collections with eval and join tables
<pre class='prettyprint' language='ruby'>def move_old_collection_to_new_collection @old_collection = CollectionOne.find(params[:collectionone_id]) @new_collection = CollectionTwo.find(params[:collectiontwo_id]) record_types_of_join_tables = ['organization', 'event', 'program', 'person', 'project'] #ex. moving CollectionOneEvent join records to CollectionTwoEvent and so on for rt in record_types_of_join_tables collection_record_type = eval "CollectionOne#{rt.capitalize}.find(:all, :conditions => ['collection_id = ?', #{@old_collection.id}])" unless collection_record_type.empty? for c in collection_record_type record_id = eval "c." + "#{rt}" + "_id" collection2_record_type = eval "CollectionTwo#{rt.capitalize}.find(:all, :conditions => ['collection_id = ? AND #{rt}_id = ?', #{@new_collection.id}, #{record_id}])" if collection2_record_type.empty? move_collection_record_to_new_collection = eval "CollectionTwo#{rt.capitalize}.new(:collection_id => #{@new_collection.id}, " + ":" + "#{rt}_id => #{record_id})" if move_collection_record_to_new_collection.save! puts "Logging results here" end end end end end end</pre> <a href="http://www.refactormycode.com/codes/1047-moving-collections-with-eval-and-join-tables" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>