So far, it\’s RoR

Ruby on Rails, PostgreSQL, SVN, etc….

Archive for July, 2008

View for version numbers, host names, IPs, etc

Posted by Chirag Patel on July 26, 2008

Here’s some code (and rendered view) for various version numbers, host names, IPs for Ruby, Rails, PostgreSQL, SMTP.


<b>Network</b><br>
UNIX hostname: <code><%= `hostname` %></code><br>
SERVER_ADDR: <code><%= request.env[“SERVER_ADDR”].to_s %></code> <br>
HOST_NAME : <code><%= request.host %></code> <br>
REMOTE_ADDR: <code><%= request.env[“REMOTE_ADDR”].to_s %></code> <br>
<br>
<b>Software</b><br>
Database: <code><%= ActiveRecord::Base.connection.select_value(“SELECT  VERSION()”) %></code><br>
Email delivery method: <code><%= ActionMailer::Base.delivery_method %></code><br>
SMTP server: <code> <%= ActionMailer::Base.smtp_settings[:address] %></code><br>
Ruby: <code> <%= “#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) on #{RUBY_PLATFORM}” %> </code><br>
Rails: <code> <%= “#{Rails::VERSION::STRING}” %> </code><br>

Network
UNIX hostname: server1.mydomain.com
SERVER_ADDR: 10.2.128.100
HOST_NAME : www.mydomain.com
REMOTE_ADDR: 12.207.103.224

Software
Database: PostgreSQL 8.3.3 on x86_64-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
Email delivery method: activerecord
SMTP server: localhost
Ruby: 1.8.6 (2007-03-13) on x86_64-linux
Rails: 2.1.0

Posted in Uncategorized | Leave a Comment »

Using helpers in models, views, and controllers

Posted by Chirag Patel on July 8, 2008

Using this as a guide JLHPBv2: Using Helpers in Models in Rails, you can make a single Module that can be accessed from models, views, and controllers. The helpers automatically created in app/helpers/*_helpers.rb   might also be available anywhere as long as you include them.

I decided to make the methods in the helper class-scoped (using self below) so that the origin of the helper method is explicitly obvious in the call (eg. to_s below)

app/lib/utility_helper.rb
module UtilityHelper
  def self.camelcase_to_spaced(word)
    word.gsub(/([A-Z])/, " \\1").strip
  end
end

app/models/event.rb
class Event < ActiveRecord::Base
  include UtilityHelper
 
  def to_s
    UtilityHelper.camelcase_to_spaced("This an Event object")
  end
end

app/helpers/events_helper.rb
module EventsHelper
  include UtilityHelper
end

app/controllers/event_controller.rb
class EventController < ApplicationController
  include UtilityHelper
end


app/views/events/index.html.erb
<%=UtilityHelper.camelcase_to_spaced(event[:event_type])%&rt;

Posted in Ruby on Rails, Uncategorized | 2 Comments »