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 # paste in your model 2 3 validates :url, :presence => true, :format => { :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix }
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"
1 require 'active_record' 2 3 ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :host => 'localhost', :user => 'root', :password => 'mypass', :database => 'mydatabase') 4 5 class User < ActiveRecord::Base ; end 6 7 puts User.count 8 #=> 9
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) }