how to use number_to_currency in controller
1 include ActionView::Helpers::NumberHelper
1 include ActionView::Helpers::NumberHelper
1 def rand_str(length) 2 return rand(36**length).to_s(36) 3 end
1 def random_password(size = 8) 2 charset = %w{ 2 3 4 6 7 8 9 A B C D E F G H J K L M N P Q R T V W X Y Z} 3 (0...size).map{ charset.to_a[rand(charset.size)] }.join 4 end
1 validates :login, :presence => true, :length => {:minimum => 4}, :uniqueness => true, :format => { :with => /[A-Za-z0-9]+/ } 2 3 # :presence => true 4 # :uniqueness => true 5 # :numericality => true 6 # :length => { :minimum => 0, maximum => 2000 } 7 # :format => { :with => /.*/ } 8 # :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } # email format 9 # :format => { :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix } # url format 10 # :inclusion => { :in => [1,2,3] } 11 # :exclusion => { :in => [1,2,3] } 12 # :acceptance => true 13 # :confirmation => true
1 validates :price, :presence => true, :format => { :with => /[0-9\,]*/ }
1 Object.methods.grep /inspect/ 2 => ["inspect", "pretty_inspect", "pretty_print_inspect"]
1 >> url = "http://www.codestacker.com/tag/ruby" 2 >> url[/https?:\/\/.[^\/]+/] 3 => "http://www.codestacker.com"
r – Open a file for reading. The file must exist.
w – Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
a – Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.
r+ – Open a file for update both reading and writing. The file must exist.
w+ – Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
a+ – Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.
1 doc = "hello world" 2 3 File.open(my_file, 'w') {|f| f.write(doc) }
1 def humanize secs 2 [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name| 3 if secs > 0 4 secs, n = secs.divmod(count) 5 "#{n.to_i} #{name}" 6 end 7 }.compact.reverse.join(' ') 8 end 9 10 p humanize 1234 11 #=>"20 minutes 34 seconds" 12 p humanize 12345 13 #=>"3 hours 25 minutes 45 seconds" 14 p humanize 123456 15 #=>"1 days 10 hours 17 minutes 36 seconds" 16 p humanize(Time.now - Time.local(2010,11,5)) 17 #=>"4 days 18 hours 24 minutes 7 seconds"
1 Pony.mail(:to => 'email@provider.com', :via => :smtp, :via_options => { 2 :address => 'smtp.gmail.com', 3 :port => '587', 4 :enable_starttls_auto => true, 5 :user_name => 'id_gmail', 6 :password => 'parola_gmail', 7 :authentication => :plain, # :plain, :login, :cram_md5, no auth by default 8 :domain => "HELO", # don't know exactly what should be here 9 }, 10 :subject => 'hi', :body => 'Hello there.')