Thursday, January 28, 2010

Models and Default Values

Couple notes:

script/console:
1. reload! - reload all the Rails stuff
2. Model_name.destroy(id_number) - delete an object from a table

Model Validation:
validates_presence_of :url <-- look at spelling of presenCe!!
validates_uniqueness_of :url
See http://juixe.com/techknow/index.php/2006/07/29/rails-model-validators/
also in Model file is Default Values
before_save :default_values
def default_values
if self.column_name == nil
self.column_name = 'hello'
end
nil
end

before_save will let me execute a function before the object gets saved (new or update). I check to see if a value is designated. If not, use the default value.
Use 'nil' at the end to account for strange behavior with a boolean getting set to false. See http://www.neeraj.name/blog/articles/838-before_save-callback-be-careful-accidentally-do-not-return-false

Tuesday, January 26, 2010

To do

1/26
  • Add default values for Site model. There was an error during load of main page, apparently because of nil values. - DONE

Monday, January 25, 2010

Installation

Mainly used instructions from https://help.ubuntu.com/community/RubyOnRails

Some problems with installing and using RubyGems. Followed direction from http://railsforum.com/viewtopic.php?id=34044, which states that I should install from source. Again, ubuntu site had such instructions (wget, tar, etc)

Edit apache config file, /etc/apache2/apache2.conf:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger
-2.2.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.9
PassengerRuby /usr/bin/ruby1.8

Create new file in /etc/apache2/sites-available/larrychang.dyndns.org:

ServerName ror.myhost.com
DocumentRoot /home/myuser/www/mynewapp/public
RailsEnv development


sudo a2enmod rewrite
sudo a2ensite ror.myhost.com
sudo apache2ctl restart

other notes:
http://httpd.apache.org/docs/2.0/vhosts/examples.html#port
file is at /etc/apache2/apache2.conf
/etc/apache2/sites-available