Installing Ruby on Rails Plugins via MediaTemple

May 10th, 2009

Good Morning and Happy Mothers Day!

I have been running Ruby on Rails on my Mac, playing around with applications, getting familiar with the framework. I recently started a Ruby on Rails project for a client and I told the client to switch over to MediaTemple, the best decision ever made. All of the controls and support are amazing. I was trying to run this command to install Restful Authentication:

./script/plugin install git://github.com/technoweenie/restful-authentication.git

The main issue to make sure to be aware of is to change to your containers directory using this via Terminal:

cd $HOME/../../containers

If you do run:

ls

You should now see a listing of any containers you have purchased in my case mine returns:

rails

Change directories for you are inside your rails application and now run:

./script/plugin install git://github.com/technoweenie/restful-authentication.git

You should be golden! Hope this helps out some people with any issues they may have. I should also add in that the command will generate your controllers/models, best of luck!

./script/generate authenticated user sessions

Active Record Already Activated

May 4th, 2009

After spending hours and hours staring at line after line of SSH into my MediaTemple Ruby On Rails Container, I finally found a solution for this stubborn error that kept developing in my mongrel log on application start:

/home/XXXXX/data/rubygems/lib/rubygems.rb:149:in `activate’: can’t activate activerecord (= 2.3.2, runtime), already activated activerecord-2.1.0 (Gem::Exception)

I have tried a whole slew of commands to try and fix this. First, I tried running:

gem cleanup

Still got that same error when I tried starting my application I made sure that my environment.rb was called the correct version of Rails that I had installed. This command seem to get me in the right direction:

rake rails:freeze:gems

Before running this, call the following code from your applications root directory:

rm -rf vendor/rails/

This will remove the folder “rails”, then you can continue with running the rake command. After running rake freeze, I got an error, saying it couldn’t find any rake files. I got this output:

Freezing to the gems for Rails 2.3.2
rm -rf vendor/rails
mkdir -p vendor/rails
cd vendor/rails
ERROR: Gem ‘activesupport’ not installed.
mv activesupport
rm -rf vendor/rails
rake aborted!
undefined method `to_str’ for nil:NilClass

Specifying a version to the rake freeze command this work like a charm, I simply ran:

rake rails:freeze:edge RELEASE=2.1.2

Started my application, checked my mongrel log, no errors on start up. I browsed to my URL and it worked. Hopefully this can help you fix your problem and relieve any headaches. If I missed anything that can help other people out, let me know. The joys of coding continue…

Validating with Rails

November 4th, 2008

Ruby on Rails is one of the more popular MVC frameworks out there along with .NET, Zend, and CakePHP. Every day more and more resources are being published regarding Ruby on Rails. One of the nice things about Ruby on Rails is that it makes easy to help validate forms within your rails application. If you want to check for the presence of text for a field it would be something like:

validates_presence_of :comment

That checks for the field name comment, like in the code snippet below. This will produce the input tag using rails.

<%= text_field "comment", "comment" %>

The other section to make it all run is the

<%= error_messages_for 'model_name' %>

Place this line of code at the top of your form, and replace “model_name” with the model name your application refers too. It tells the application to look at the validation rules you set up. Once you have those in place, you should not be able to submit the form with a blank input.

A few other predefined rules built in to Ruby on Rails are:

Field should not be empty

Code: validates_presence_of
Example: validates_presence_of :user_name, :password

Field should Numerical

Code: validates_numericality_of
Example: validates_numericality_of :value

Field should not be Unique

Code:validates_uniqueness_of
Example: validates_uniqueness_of :user_name

Field Need to be of size X

Code: validates_length_of
Example: validates_length_of :state_code, :is=>2

Field size Need to be of between X to Y

Code: validates_length_of
Example: validates_uniqueness_of :user_name

To learn more about validation and to read up on the rest of the Rails API, read this