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!
More Jobs
Recent
Too many assignments and conditional statements
Cryptography with RSA and Base64
A Rails rake task to lookup status codes.
Code to detect the web browser
Base class for easy class property handling
Your average file filter...
simplify multiple gsub
Parse XML from Yahoo weather RSS feed
Base64 image encoding and image hash
Query TinyUrl the fastest way
Popular
Code to detect the web browser
simplify multiple gsub
Too many assignments and conditional statements
Your average file filter...
A Rails rake task to lookup status codes.
Query TinyUrl the fastest way
Base64 image encoding and image hash
Parse XML from Yahoo weather RSS feed
Base class for easy class property handling
Cryptography with RSA and Base64
Pastable version of
Dynamic migrations for rails
<div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26</pre> <pre class="sunburst"><span style="color:#E28964;">require</span> <span style="color:#65B042;"><span style="color:#65B042;">'</span>erb<span style="color:#65B042;">'</span></span> <span style="color:#E28964;">class</span> <span style="text-decoration:underline;">ClientMigrator</span> <span style="color:#E28964;">def</span> <span style="color:#89BDFF;">self.create</span>(<span style="color:#3E87E3;">fields</span>) erb_migration <span style="color:#E28964;">=</span> <span style="color:#3E87E3;">ERB</span>.<span style="color:#89BDFF;">new</span> <span style="color:#65B042;"><span style="color:#65B042;"><<-EOS</span></span> <span style="color:#65B042;"> class AddClients < ActiveRecord::Migration</span> <span style="color:#65B042;"> def self.up</span> <span style="color:#65B042;"> create_table :clients do |t|</span> <span style="color:#65B042;"> <% fields.each do |name, type| %>t.column :<%= name %>, :<%= type %></span> <span style="color:#65B042;"> <% end %></span> <span style="color:#65B042;"> end</span> <span style="color:#65B042;"> end</span> <span style="color:#65B042;"></span> <span style="color:#65B042;"> def self.down</span> <span style="color:#65B042;"> drop_table :clients</span> <span style="color:#65B042;"> end</span> <span style="color:#65B042;"> end</span> <span style="color:#65B042;">EOS</span> <span style="color:#65B042;"> File.open("db/migrate/003_add_clients.rb", "w+") do |f|</span> <span style="color:#65B042;"> f.puts erb_migration.result(binding)</span> <span style="color:#65B042;"> end</span> <span style="color:#65B042;"> `rake db:migrate`</span> <span style="color:#65B042;"> end</span> <span style="color:#65B042;">end</span> <span style="color:#65B042;"></span> <span style="color:#65B042;"># Example call</span> <span style="color:#65B042;">ClientMigrator.create(:name => :string, :phone => :string)</span> </pre> </div> </div> <a href="http://refactormycode.com/codes/78-dynamic-migrations-for-rails" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://refactormycode.com/images/small_logo.gif" style="border:0" /></a>