Sw33tCode

Smart code for developers

Sw33tCode header image 1

Installing Ruby on Rails with Lovdbyless on a Windows machine

April 13th, 2008 · 14 Comments

I know a lot of people who use ruby are either doing their development on linux machines or macs, but for those people who are brave….. here is a guide for you setting up LovdByLess with Ruby on Rails on Windows machine. The machine I used is Windows XP.

LovdByLess is built with Ruby on Rails and is a social networking solution that has everything you need to build your community.
The folowing installation of Ruby and Ruby on Rails was created with guidance from the RubyOnRails.org documentation which can be found here.

Install Ruby compiler
For Windows I used the One-Click Installer - Windows found here: rubyforge.org(Which for me at the time of this post was version ruby186-26)

I like to be able to run ruby from where ever I am in the command prompt so in order to do that just add this line (if not there already) to your Path variable in the System Variables:
c:\ruby\bin;

Setup RubyGems and Rails on Ruby
Download from here rubyforge.org the latest release of Ruby gems. I used the zip version 1.1.0 for this installation. Extract the zip file to where ever you want. Open a console (cmd.exe) window and proceed to where you extracted the rubygems 1.1.0. Run this command:
c:\[rubygems 1.1.0 Path]\ ruby setup.rb

Now we want to setup Rails. Just type this in the command prompt:
gem install rails --include-dependencies

Download and extract the zip file from LOVDbyLESS.

We have to install the following gems using the RubyGems program we just installed. From the command prompt, run the following:
c:\gem install youtube-g
c:\gem install rflickr
c:\gem install uuidtools
c:\gem install colored
c:\gem install hpricot
c:\gem install mocha
c:\gem install redgreen
c:\gem install RedCloth
c:\gem install acts_as_ferret
c:\gem install ferret
c:\gem install win32console
c:\gem install avatar
c:\gem install tzinfo
c:\gem install rails

****If you get asked during these gem installations to Install hoe, rubyforge, Rake, mime-types, xml-simple, etc just type Yes for these.****

Get rmagick gem here, download and extract. Execute:
ImageMagick-6.3.7-8-Q8-windows-dll.exe
In the console change directory to where you extracted the gem.
gem install rmagick-2.0.0-x86-mswin32
This will require a reboot of your machine at some point before you try to use this gem. (Trust me. this took me a long time to figure out!)

We need to create a mysql user account to run the LovdByLess database with. This assumes you have Mysql running on your machine. From the command prompt type and hit enter:
mysql --user=root mysql -p
Enter your password. Create mysql user:
GRANT ALL PRIVILEGES ON *.* TO 'lovdbyless'@'%'
IDENTIFIED BY 'my_password' WITH GRANT OPTION;

Then exit mysql:
quit mysql

Go to the directory where you extracted LovdByLess and open the config folder. Copy database.yml.tmp to database.yml. Edit this file and replace the values for username and password with the mysql user you created above.

From the command prompt, proceed to your LovdByLess directory, run the following:
rake db:create:all
rake db:migrate a=no
rake

The last command should run all ruby tests for the project. Now run this from your lovdbyless folder in the command console:
ruby script\server
The rails server is now up and running. Open up a web browser and go to this address:
http://localhost:3000/

Please let me know if you had any issues setting this up. Thanks!

→ 14 CommentsTags: Mysql · Ruby · Ruby On Rails

Building Mysql Database contents from batch script in Windows

April 5th, 2008 · 2 Comments

I needed a way to build my database quickly on a project I was working on and I was constantly making changes to the database that supplied content to my application. So I came up with an easy batch script that would help facilitate the changes in my database environment.

Here is a mocked version of the batch script that I wrote to build the database:

@echo off
 
REM: Command File Created To Create MySQL Experiments Database
REM: Date Generated: 4/5/2008
REM: Usage: CommandFilename [Host] [Username] [Password]if '%1' == '' goto usage
 
if '%2' == '' goto usage
if '%3' == '' goto usage
if '%1' == '/?' goto usage
if '%1' == '-?' goto usage
if '%1' == '?' goto usage
if '%1' == '/help' goto usage
 
echo experiments.build.database START
mysql -h %1 -u %2 -p%3 > "experiments.build.database.sql"
if %ERRORLEVEL% NEQ 0 goto errors
echo experiments.build.database END
 
echo experiments.build.tables START
mysql -h %1 -u %2 -p%3 "experiments" > "experiments.build.tables.sql"
if %ERRORLEVEL% NEQ 0 goto errors
echo experiments.build.tables END
 
echo building stored procedures START
mysql -h %1 -u %2 -p%3 "experiments" > "sprocs\uspAddUser.sql"
if %ERRORLEVEL% NEQ 0 goto errors
echo uspAddUser
echo building stored procedures END
 
echo experiments.insertdata.messenger START
mysql -h %1 -u %2 -p%3 "experiments" > "experiments.insertdata.sql"
if %ERRORLEVEL% NEQ 0 goto errors
echo experiments.insertdata.messenger END
 
echo Finished Building Database 
 
goto finish
REM: How to use screen
 
:usage
echo.
echo Usage:    MyScript Server Database
echo Host:     MySQL Server
echo Database: the name of the target database
echo Username: username to be used on target database
echo Password: password to be used on target database
echo.
echo Example: BuildDatabase.cmd "localhost" "root" "password"
echo.
echo.
goto done
 
REM: error handler
:errors
echo.
echo WARNING! Error(s) were detected!
echo --------------------------------
echo Please evaluate the situation and, if needed,
echo restart this command file. You may need to
echo supply command parameters when executing
echo this command file.
echo.
pause
goto done
 
REM: finished execution
:finish
echo.
echo Script execution is complete!
 
:done
@echo on

This script will call the sql files that contain the commands to build the database, tables, stored procedures, and even create some test data. To call this command file all you have to do is supply the host, username, and password parameters. Like this:

c:\BuildDatabase.cmd "localhost" "root" "password"

This script example will call your database: experiments. But if you wanted to dynamically name your database you can just add another parameter onto your batch script and replace all the mysql calls above with this code:

mysql -h %1 -u %2 -p%3 %4  > "sql_code.sql"

Then your call to the command file will be like this:

c:\BuildDatabase.cmd "localhost" "root" "password" "database_name"

If you wish to try out the code in action please download the zip file below. You will need MySql Version 5 or above to test this. Please let me know if you have any questions.

Sample Mysql Batch Script

→ 2 CommentsTags: Mysql · Windows Batch Script