


validates_length_of :name, :maximum => 15, :allow_blank => true
user = User.new(:name => "")
user.valid? #=> true
gem install activerecord-oracle-adapter
gem install activerecord-sqlserver-adapter
gem install activerecord-firebird-adapter
gem install activerecord-frontbase-adapter
gem install activerecord-openbase-adapter
gem install activerecord-sybase-adapter
<%= render :partial => 'user_info', :layout => 'boxed', :locals => {:user => @user} %>
class ApplicationController < ActionController::Base
# Our many helpers that need to be available throughout the app
[:formatting, :highlighting, :i18n].each { |h| helper h } ...
end
class ApplicationController < ActionController::Base
# Make all helpers in app/helpers/**/ available
helper :all ...
end
a={'1'=>'one','2'=>'two','3'=>'three','4'=>'four'}
y a
puts a.to_yaml
usage: puts a
output:
1one2two3three4four
Using y or to_yaml
usage: y a or puts a.to_yaml
output:
"1": one
"2": two
"3": three
"4": four
pp a
output:
{"1"=>"one", "2"=>"two", "3"=>"three", "4"=>"four"}
usage: puts a.inspect
output:
{"1"=>"one", "2"=>"two", "3"=>"three", "4"=>"four"}
a = [ "a", "b", "c" ]
a.freeze
a << "z"
Will return
`<<': can't modify frozen array
parent_record = User.find(1)
new_user = User.new(parent_record)
new_user.name = 'new_name'
new_user.save
new_user = User.new(parent_record.attributes)
ALTER DATABASE yourDBname SET EMERGENCY2) Bring DB to single user mode.
ALTER DATABASE yourDBname SET SINGLE_USER
3)Repair you DBDBCC CheckDB ('yourDBname', REPAIR_REBUILD)
if the above command fails, try thisDBCC CheckDB ('yourDBname', REPAIR_ALLOW_DATA_LOSS)
NOTE : This may result in dataloss
4) Bring you DB to multi user modeALTER DATABASE yourDBname SET MULTI_USER
By now you should have your DB up & running.
DB at times enter into SUSPECT mode - restarting server should solve them if not follow the above steps.
To be on safer side take full / transactional backups regularly
ActiveRecord::Base.class_eval do
def attributes_from_column_definition_with_null_fix
returning attributes = attributes_from_column_definition_without_null_fix do
attributes.each_value { |value| value.replace('') if value == 'NULL' }
end
end
alias_method_chain :attributes_from_column_definition, :null_fix
end
require 'rubygems'
require 'rake'
require 'rufus/scheduler'
load File.join( RAILS_ROOT, 'lib',
'tasks', 'my_task.rake')
scheduler = Rufus::Scheduler.start_new
scheduler.cron("0 17 * * 0") do
Rake::Task["maintenance:delete_order_files"].invoke
end
require 'rubygems'
require 'rake'
require 'rufus/scheduler'
load File.join( RAILS_ROOT, 'lib',
'tasks', 'mytasks.rake')
# Note include file containing your rake tasks
# Else you will get - Don’t know how to build
#task XXXXX’ error for the tasks you
#have defined
scheduler = Rufus::Scheduler.start_new
scheduler.every("1m") do
puts "Scheduler invoked"
end
task :my_first_rake_task do
puts "This is my first rake code"
end
namespace :test do
task :my_first_rake_task do
puts "This is my first rake code"
end
end
namespace :test do
desc "This is a simple example to show the usage of rake tasks in rails"
task :my_first_rake_task do
puts "This is my first rake code"
end
end