activerecord · multiple-models · Rails · rails-environments · rubyonrails

How to find different environment configurations in rails

While working with a multiple-database application I came across the point where I had to juggle between different environment configurations. I had to pass connection hash to ActiveRecord::Base.establish_connection, something like this: ActiveRecord::Base.establish_connection ( :adapter=>"mysql", :host=>"localhost", :username=>"myuser", :password=>"mypass", :database => "somedatabase" ) This connection can be easily retrieved from ActiveRecord::Base.configurations, this is currently undocumented. Using ActiveRecord::Base.configurations,… Continue reading How to find different environment configurations in rails

ActiveSupport · Rails

Defining customized Date / Time format in Rails

Generally to display customized Date / Time in rails we use helper method like: # formats the date def show_date(date)   date.strftime("%B %d, %Y") end But there is another better way to do this, injecting customized rules in respective DATE_FORMATS hash of ActiveSupport::CoreExtensions module. # define this in your environment.rb # Default date/time format ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(:standard… Continue reading Defining customized Date / Time format in Rails

localhost · mail server · Rails

Configuring Java Email Server for use with Rails

Configuring Java Email Server for use with Rails is easy, it's pretty straight forward and simple. Step 1: Install Java Email Server. Step 2: Edit your development.rb like this : config.action_mailer.delivery_method = :smtp config.action_mailer.raise_delivery_errors = true config.action_mailer.server_settings = { :address => "sazwqa@localhost" , :port => 25, :domain => "localhost" , :authentication => :login, :user_name =>… Continue reading Configuring Java Email Server for use with Rails