Strip html in ruby
def h(string) string.gsub(/<\/?[^>]*>/, "") end
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
def h(string) string.gsub(/<\/?[^>]*>/, "") end
passenger-memory-stats passenger-status
RailsSpawnMethod conservative
begin
raise "boom"
rescue => detail
RAILS_DEFAULT_LOGGER.info detail.backtrace.join("\n")
end
Dir['*/*/*'].grep(%r{[^/]+/[^/]+/\d+}).map { |s| [s.sub(/\d+$/, ''), $&.to_i] }\ .map { |s, n| ["#{s}#{n}", (d = "#{s}%04d" % (n / 10000)), "#{d}/%04d" % (n % 10000)] }\ .each { |f, d, t| `mkdir -p #{d} && mv #{f} #{t}` }
class UpgradeFileColumns < ActiveRecord::Migration def self.up # note I use a custom store path here Dir.chdir("#{RAILS_ROOT}/public/files") Dir['*/*/*'].grep(%r{[^/]+/[^/]+/\d+}).map { |s| [s.sub(/\d+$/, ''), $&.to_i] }\ .map { |s, n| ["#{s}#{n}", (d = "#{s}%04d" % (n / 10000)), "#{d}/%04d" % (n % 10000)] }\ .each { |f, d, t| `mkdir -p #{d} && mv #{f} #{t}` } end def self.down end end
for f in *.erb; do mv $f `basename $f .erb`.haml;done;
def link_button_to(name, options = {}, html_options = {}) url = url_for(options) html_options["onclick"] = "javascript:document.location.href='#{url}'; return false;" html_options.merge!("type" => "button", "value" => name) tag("input", html_options) end
def snippet(text, wordcount, omission) text.split[0..(wordcount-1)].join(" ") + (text.split.size > wordcount ? " " + omission : "") end
<%= snippet(@post.body, 50, "#{link_to "Read more...", @post}") %>
STATES = [ [ "Alabama", "AL" ], [ "Alaska", "AK" ], [ "Arizona", "AZ" ], [ "Arkansas", "AR" ], [ "California", "CA" ], [ "Colorado", "CO" ], [ "Connecticut", "CT" ], [ "Delaware", "DE" ], [ "Florida", "FL" ], [ "Georgia", "GA" ], [ "Hawaii", "HI" ], [ "Idaho", "ID" ], [ "Illinois", "IL" ], [ "Indiana", "IN" ], [ "Iowa", "IA" ], [ "Kansas", "KS" ], [ "Kentucky", "KY" ], [ "Louisiana", "LA" ], [ "Maine", "ME" ], [ "Maryland", "MD" ], [ "Massachusetts", "MA" ], [ "Michigan", "MI" ], [ "Minnesota", "MN" ], [ "Mississippi", "MS" ], [ "Missouri", "MO" ], [ "Montana", "MT" ], [ "Nebraska", "NE" ], [ "Nevada", "NV" ], [ "New Hampshire", "NH" ], [ "New Jersey", "NJ" ], [ "New Mexico", "NM" ], [ "New York", "NY" ], [ "North Carolina", "NC" ], [ "North Dakota", "ND" ], [ "Ohio", "OH" ], [ "Oklahoma", "OK" ], [ "Oregon", "OR" ], [ "Pennsylvania", "PA" ], [ "Rhode Island", "RI" ], [ "South Carolina", "SC" ], [ "South Dakota", "SD" ], [ "Tennessee", "TN" ], [ "Texas", "TX" ], [ "Utah", "UT" ], [ "Vermont", "VT" ], [ "Virginia", "VA" ], [ "Washington", "WA" ], [ "West Virginia", "WV" ], [ "Wisconsin", "WI" ], [ "Wyoming", "WY" ] ] <%= form.select :state, STATES, :include_blank => true %>
<%= error_messages_for :order, :header_message => "Please Try Again!", :message => "We had some problems saving your information:" %>