SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Saturday, June 6, 2009

Tips and Tricks


Start irb with tab completion enabled

irb --readline -r irb/completion

Executing shel commands in ruby


system "curl http://www.google.com"

Combination of in_groups_of and cycle helper


<table><% articles.in_groups_of(2, false) do |row_tasks| %><tr><%row_tasks.each do |task| %><td style="background-color:<%=cycle("red","white","blue") %>"><%= task.title %></td><% end %></tr><% end %></table>

Customized error fields


ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag| if html_tag =~ /type="hidden"/ || html_tag =~ /<label/ html_tag else "<span class='error_message'>#{[instance_tag.error_message].flatten.first.sub(/^\^/, '')}</span>" + "<span class='field_error'>#{html_tag}</span>" endend

Removing remote branch from GIT


git push git@github.com:genlinux/Freelance.git :heads/rubyist.rb

! [rejected] master -> master (non-fast forward)


git push origin +master:master

2 comments :

  1. Just put this in your ~/.irbrc file:

    require 'irb/completion'
    require 'irb/ext/save-history'

    ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
    IRB.conf[:SAVE_HISTORY] = 100
    IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"

    ReplyDelete
  2. Removing p tags from text

    text.gsub(/(^[ ]*<p>[ ]*)|([ ]*<\/p>[ ]*$)/, '')

    ReplyDelete