So I just launched some new features to cwol.tv and determined that my current admin dashboard was insufficient for getting a good overview of what was happening with the site.

I have spent most of the morning making it more useful, only to find out that my trusty killall -9 dispatch.fcgi was no longer working. Hrm, could it be because I am now using passenger? I think so.

If you are running into the same issue with your Site5 account you can do a reset on the ruby framework as well. Use killall -9 ruby instead and that will take care of your framework reset issues. A little note: You might see an ugly Passenger screen, just refresh the screen one more time and your changes will be applied.

I have not fallen off the face of the earth (just moved to Hawaii since my last post), I have also been coding like a mad man on a new addition to my CWOL.TV (Championship Wrestling Online) web site.

The new addition is a fantasy wrestling component that allows one to start a career and build it. It is a time based game that doesn’t stop. As one progresses in levels, they earn the opportunity to gain more wrestling moves, holdings (items that earn one income) and the ability to fight harder matches.

So, for the past couple of months I have been cranking out the code.

Now for the great news. The past few launches of web sites have been a pain to say the least. I blasted Site5 on more than one occasion. THAT HAS CHANGED!! Site5 has really stepped up their game with regard to rails hosting.

This was by far the easiest update I have ever done.

I do not say that lightly. The previous version of the site was still running on Rails 1.2. (What a difference 7 months can make).

The latest iteration of the site was a complete upgrade in development to Rails 2.3.2.

It was a seamless setup. I had to kill the old directory and start all over. Needless to say, it works great. I have been tailing the production log file to hopefully see the first person to come to the site since the launch. I hope this is what will put me over with regard to 1000 unique visitors in one month.

Here is to hoping.

Posted by: tszao | February 21, 2009

Site5 MySQL Rails 2.2.2 Truncate and RMagick upgrade hell

So this has been the month from hell for me as far as hosting with Site5. I thought it was bad trying to figure out how to get a site set up in a Rails 2.2.2 environment. That is nothing compared with dealing with the frustration of a MySQL upgrade while on vacation and an upgrade to Rails 2.2.2 while over seas.

In both cases, the internet access is limited and I only have a small amount of time each day to dedicate to working on the sites I manage. I would love to actually be upgrading the sites and not dealing with the fixes caused by the hosting company.

I think the worst part of all of this is that Site5 didn’t send a notification (may have posted it in the forums, I don’t know, but who checks the forums every day) to let me know that the upgrades were happening. I was scrambling to find out what was going on.

Here are a few things I ran into.

MySQL – The storage engine hung the database some how during the upgrade. This did not happen for the one PHP site I have on the server. I submitted a ticket and they were able to restore from a back up. I had two rails sites that this issue affected.

Upgrade to Rails 2.2.2 – This upgrade would have worked great if I was not using the RMagick gem. It is a great thing that I have about 5 different sites with 5 different configurations. Some sites worked and some did not.

With the first ticket I submitted it was assumed that my site was not compatible with the upgrade and I was told to freeze my gems. This didn’t make sense as I had 2 other sites that went through the upgrade just fine. After digging deeper, I noticed that my RMagick was hosing the site. So I submitted another ticket suggesting that RMagick and the gem for RMagick were out of sync. It was nice to see a response in the ticket that said they had upgraded the gem and all worked well again. Just as a side note, if you freeze your local gem for RMagick and it is different than the RMagick version on the server, your site will fail to start up as well.

The final issue I ran into is that I use the truncate method on the home page of the CWOL.TV site. Well after doing some research Rails 2.2.2 and Ruby 1.8.7 do not agree with regard to the truncate method. I tried several work arounds and none of them worked. If you have a suggestion that will work in a shared hosting environment, I am open to it From what I can tell, the recommendation is to downgrade to Ruby 1.8.6. Good luck trying to get a hosting company to go backwards on dozens if not hundreds of servers.

For now I had to eliminate the truncate code from the site and work on another solution. It will really suck if I have to write my own truncate method to work around this mess.

Well I am done venting for a while. I hope that you do not think I am down on Site5. I love the company and when you get someone who knows what they are doing in tech support you can usually get things done pretty quickly. But if there was one area that could stand to be improved it would be communication.

So I learned another little fact about rails, puts and apache. In a production environment, they do not agree.

I just made a bunch of changes for the wrestling website that I have been working on and finally got them all uploaded. When I went to check to see if they are working on the server I was shocked to find out that my carefully laid plans had failed miserably.

Debugging in a live environment can be a very stressful endeavor.

Of course the code works in development but in live (because I do not have a staging environment that is exactly like my production) things can still go wrong. So, as I sift through the code I start with things left in that don’t need to be there.

As it turns out I had a puts statement that was left over from debugging and it was causing the server to have some major fits.

Moral of the story, remove your puts statements before you go live with the code.

Posted by: tszao | January 3, 2009

Use Notepad ++ to tail log files in Windows

So you want to be able to tail a log but you are developing in a windows environment. In the past you had to install cygwin to make that happen. Today that isn’t the case.

I am not sure how long this has been in place but the guys at Notepad++ have really out done themselves.

When developing in rails, it is nice to see what the development.log is showing. With most text editors you have to either refresh the text or close the editor and reopen it. In either case you still have to scroll to the bottom of the log.

With Notepad ++ 5.1 (which is what I am using) the log automatically updates and all you have to do is go view it. If this feature has been in place for a long time, GREAT!!!

However, when someone doesn’t know it is there, it is like putting glasses on and noticing how beautiful trees are for the first time.

So launching a new web site can, in no particular order, be tedious, fun and exciting. It is fun during the development process to see the site come together and start taking on a life of its own.

What is more fun is to actually launch the site on time. It has been a while since I lunched a website (well, something that I have developed and not used prefabbed templates). Langorang (the language news site) was my first (since I started the home projects again) over a year ago.

I have had sites die, some are just moving along gradually (very gradually) building traffic. Others still will never be seen as a development of mine again. Gone are the days of owning 20 or 30 domain names hoping that I will build a site for each.

I have settled down and started working on one site or idea at a time. I have committed to only launching a site if there is a way to effectively manage it and I have finally gotten the instant-millionaire idea out of my head. One of my former employers used to say that it took 15 years for him to become an overnight success. I think I finally understanding them meaning of consistency over time multiplied by God. Took me long enough.

So, finally, after 10 months of development, 5 computer reformats, 1 hard drive crash and a complete rewrite of the original concept, I am proud to launch Championship Wrestling Online.TV (CWOL.TV).

CWOL.TV is a social networking site that allows professional wrestling fans host their own promotion. Each promotion comes complete with tools to manage live events, matches, wrestlers, titles, pictures, and videos.

The site just launched yesterday and the code is still in its infancy. I know there will be a lot of work to do if any significant amount of traffic starts to show up but for now I am enjoying the latest fruits of my labor.

I have been using Site5 for over a year now and their system has been running Rails 1.2 since I started.  Well, they now have some Rails 2.2.2 servers and it took me a week to get everything figured out so that I could get a client site setup.  Here are the steps that I went through.

Setting up a web site on a Site 5 Rails 2.2.2 server.

The first thing you will need to do is setup your production database. This will be important later in the process of setting up your site.

Login to your Site5 account with your favorite SSH tool.

At any point you can use the command

$ cd ~

to get back to your root directory.

The first thing you will need to do is to run the rails script with the mysql database flag.

$ rails -d mysql nameyoursite

You will see a series of create statements and will also have a new directory.

Change directories into your new nameyoursite directory
$ cd ~/nameyoursite

Next add a controller that will be used later.
$ ruby script/generate controller site index

If all goes well, you will see the script run and add some more files to your system.

You will now need to move to the config directory to take care of a few things there.

$ cd ~/nameyoursite/config

In this directory, the first file to edit is the database.yaml. I use nano, others use VI. I say use whatever makes you comfortable.

$ nano database.yml

Ok, this is where it gets a little harry. In previous versions of Rails on Site5, the only thing you had to change was the values of the production database. However, all of the extra code causes errors with starting up the rails environment. Here is the only code you will need.

production:
adapter: mysql
encoding: utf8
database: nameyoursite_databasename
pool: 5
username: username
password: password
socket: /tmp/mysql.sock

NOTE: This is important. I am not sure this is the case for all of the servers, however I found it to be true on the one I was working on. You will need to use the username and password that Site5 sent you for the SiteAdmin. The “additional users” for the database do not work as of the writing of this how-to.

After you have made the changes, save the file and exit.

Next you will need to edit the environment.rb file.

$ nano environment.rb

Remove the # from the line that looks like this

# ENV['RAILS_ENV'] ||= ‘production’

and make it look like this

ENV['RAILS_ENV'] ||= ‘production’

Again save the changes and exit.

Now change directories back to the root of your site.

$ cd ~

Next, create a symbolic link, or symlink if you prefer, that will map your public directory to the public_html directory. It is important to note when creating the symlink to use a shorter name on the mapped name. I am not sure why and if someone could explain it to me I would greatly appreciate it.

$ ln -s nameyoursite/pubilc/ public_html/nys

Now change the file permissions to make them executable with the system.

$ chmod -R 755 nameyoursite/*

From here you will want to make a back up of your public_html directory and to do that you can run the following command from the ~ directory.

$ mv public_html public_html_back

When that is completed you will now create a new symlink form your application public directory to the a linked public_html directory in the ~ of your site.

$ ln -s ~/nameyoursite/pubilc ~/public_html

Now you will need to add a .htaccess file to the application public directory.

This is what the file will look like.

—- Start .htaccess file – copy below this line —


# General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
#
# Example:
# RewriteCond %{REQUEST_URI} ^/notrails.*
# RewriteRule .* - [L]
# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On
# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
# Alias /myrailsapp /path/to/myrailsapp/public
# RewriteBase /myrailsapp
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
# Example:
# ErrorDocument 500 /500.html
ErrorDocument 500 "<h2>
Application error</h2> Rails application failed to start properly”

— End .htaccess file – copy above this line —

Change directories to your application public directory.
$ cd ~/nameyoursite/public
Create a .htaccess file and populate it with the information above.
$ nano .htaccess
Save the file and exit.
Next we want to set the route to our generated controller. So go back to the config directory.
$ cd ~/nameyoursite/config
Open up the routes.rb file with your favorite editor.
$ nano routes.rb
Uncomment the following line
# map.root :controller => “welcome”
and make it look like this
map.root :controller => “site”

and finally remove the index.html file from the application public directory.

$ mv index.html index_old.html

Now all that is left is to go and visit the site to see if it all works.

I have spent most of the week trying to figure out how to submit a subscription button to PayPal and not rely on any return scripts to let me know the payment has been submitted.

I thought Javascript may have been the answer and as it turned out, it was. AJAX is my friend. For the second time this week I was able to usefully integrate AJAX into a site I am developing.

Here is the goal:
Post the subscription plan selected to the database while submitting a PayPal subscription button.

Here is one way to do it using AJAX.

First, I didn’t want to show the subscription button. I think it would be too tempting to the user. Hiding the button was accomplished using the CSS style display.


<div style="display:none">
<form id="name_of_your_form" action="action_url" method="post"> -- code for your your PayPal button
</form></div>

This will hide the button code, but still make it available for submission later. Note the id= parameter in the form tag. This will be used later when constructing the link_to_remote link.

The next thing is to write the AJAX enhanced link to make the magic work.

Rails makes this a very easy task. All you need is built into the framework. The link looks like this …


<%= link_to_remote "SUBSCRIBE", { :url => {:action => 'your_process_action', :controller => 'your_controller', :id => the_id_code_to_pass }, :complete => "$('name_of_your_form').submit()"}, :class => "css_class" %>

Note in the :complete parameter, you will need to include the name of the form you wish to submit. Also if you are using multiple forms on the page, be sure to give each form a different id value.

The controller and action will need to contain your processing code and when it is finished the link will submit your form.

Thats it. Enjoy.

Posted by: tszao | October 13, 2008

Open Office 3 works on OS 10.5

So it has been a long time coming but I finally have Open Office on my Mac. Open Office 3.0 was recently released and it finally supports OS 10.5 without issue. Well, I say that having only tried it on my machine. I was able to open up files I made in previous Windows versions of the software with ease.

Everything is in the same place and it starts up pretty quickly.

Just wanted to share with everyone that it is available.

http://www.openoffice.org/

I wonder, this is a question for the community. I normally don’t do this but is there anyone else out there who is trying to totally migrate away from a Windows environment? If so what are some of the best tools you have found for Mac, Linux or both? I am specifically looking for thigns that pertain to running the office but any input would be useful.

So this is freaking great!!! I finally learned how to manipulate data by pulling bits and pieces out of a sql statement to use in other SQL statements. Please note that I have not tried this in SQL Server 2000 but it sure works great in SQL Server 2005 and up.

Let’s say that you want to add a column to a table and then populate it with data that is in the table already. (I know redundant data, however the thought at work is that it is primer data that the end user can change as opposed to a locked value that they can do nothing with.)

This script is going to be used in an upgrade to an existing application. So if the change has already happened we want to by pass this in lieu of the current data that is in the system.

First you want to check to see of your field exists and if it does not add it.

IF not exists (select * from sys.columns where [object_id] = (
Select [object_id] from sys.tables st JOIN sys.schemas ss ON st.schema_id = ss.schema_id where st.name = 'table_name')
AND name = 'new_field_name')
BEGIN
ALTER TABLE [dbo].[table_name] ADD [new_field_name] [char](12) NULL
END
GO

Because my in house example will create temporary tables I want to check if the temp tables exist and if so drop them

IF  EXISTS (SELECT name FROM tempdb..sysobjects WHERE name like '#Temp%')
drop table #Temp
GO
IF  EXISTS (SELECT name FROM tempdb..sysobjects WHERE name like '#Temp2%')
drop table #Temp2
GO

Note the ‘%’ in my statements above. It is necessary because Microsoft adds a lot of junk to the end of the temp table.

I know the following can go several different ways. So, I am giving you the quick and dirty how to. The next thing I did was set a declaration that will be used to pull the count total out for use later in the conditional logic.

Declare @t_intTotal Int
SELECT @t_intTotal=count(unique_field_name) FROM table_name WHERE new_field_name is not null
print @t_intTotal

With normal queries we are able to set the count(unique_field_name) as intCountFieldName and use the as variable from our recordset. Not so from within SQL server. To use the data from count(unique_field_name) I had to set @t_intTotal = count(unique_field_name). This makes it available later on in the process.

Next we have to declare some more variables that will be used if all of our new field_name fields are null. (Again, think quick and dirty. Feel free to clean it up if you like.)

Declare @Count Int
Declare @LoopCount Int
Declare @populate_value char(3)
Declare @t_populate_value char(3)

Using the new @t_intTotal variable we are able to write a simple if statement and run some code if it is necessary. After the first check we have our first of 2 temp tables. The data from here will be used to create the second temp table with an identity added to it.

IF @t_intTotal = 0
Select unique_field_name -- also the seed data value
into   #Temp
from  table_name

Using the first temp table we add the identity to a second temp table. This gives us a unique key that we can loop over when trying to add data to the table that already exists. We will set the Count to the total rows from the new query and set loop count to start at 1. Note if you pull an identity field in as one of your variables you cannot do the Identity(int,1,1) id. Only one identity field per table.

IF @t_intTotal = 0
Select Identity(int,1,1) ID, unique_field_name into #Temp2 from #Temp
Set @Count = @@RowCount
Set @LoopCount = 1

Using the second temp table we are able to loop over the recordset making an update with each iteration. In my case it is important to note that unique_field_name is a unique record so that we can use it to make sure the right seed data is going into the correct column.

IF @t_intTotal = 0
While @LoopCount <= @Count
Begin
Select @t_populatevalue=unique_field_name  from #Temp2 Where ID = @LoopCount
Set @LoopCount = @LoopCount + 1
update table_name
set new_field_name = @t_populate_value
where unique_field_name = @t_populate_value
End
GO

Note that I had to add unique_field_name data as the seed data in the new_field_name column.

This may be old hat for some, but when searching the web it is near impossible to find all of this in one place. I hope that you enjoy it and can mod it for your use. Let me know what you think.

Older Posts »

Categories