Chronicling my experiences with ruby on rails, web application development/management.

Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts

Wednesday, July 1, 2009

30 days of Rails - Handling Flash Messages

So, here i am trying to expand my closed world beyond Restful_authentication and well, basically any other technoweenie based plugin. I try my hand at Clearance


Clearance is a thoughtbot based gem which authenticates users in your web app. Out of the box, it only allows for email addresses as the login ID, which is fine for my stupid app i'm making.


However, in all my years of scaffolding, i guess i've only really used flash[:notice] for displaying my flash messages on an overall layout level. Clearance has flash[:success] and flash[:error].


The reason i found this out is because my clearance_features weren't working and i was getting 8 failures, due to the fact that I was only displaying flash[:notice]. A win for BDD i tell ya.


Gee mister, how'd you fix it


Like all expert coders, i went to the one place I can trust. Twitter. I sent out a tweet which read: twitter ruby fun: lame, hack or on track? < % = flash[:notice] ||flash[:success] || flash[:failure] % >


Most people hated this code, which is fine, as that is what i wanted to hear. While it will work, if i had a need for two flash messages at once, or if i needed to expand my flash message symbols, i'd be fucked. Enter @heycarsten


This dude turned me onto a pretty sweet gist he wrote up for me. A thousand thank you sir's to him.


Gist... Break it down hammer style.


Well everytime you see me, the hammer is on dootie...ok, hammer time is over.



  1. Create a helper called flash_helper.rb and paste this gist into it.
  2. inside the layouts directory, create a folder called partials and a partial inside of your layouts folder called /layouts/partials/flash_message.html.erb.
  3. Paste this into it(stupid stupid blogger's formatting sucks ass... so you'll have to take the spaces out)
    < p id=< % = "flash_#{type}" % > >
    < % = flash[type.to_sym] % >
    < /p >

  4. In your application_controller.html.erb you'll need to add this code to display your new fancy flash messages:
    < % = flash_messages % >

  5. In your css file, now you can create styles with the id flash_whatever. I used #flash_error{background-color: red;}, etc...If you are new to css, learn up on it son.

Yeah for heycarsten and many thanks to him for allowing me to post this code.P.s., i apologize for this shitty code formatting. blogspot sucks ass.

Saturday, June 20, 2009

Rails vs Pylons - initial thoughts

I know, I know! Comparing two frameworks is bound to be riddled with generalizations that don't help anyone and obvious features that are only "ah ha" moments to the writer of the post. However, I'm going to give you an account of my initial thoughts of Pylons, as compared to ruby on rails, a framework that I've been using for a year and a half.



Comparing Pylons to Ruby on Rails


Initial thoughts are how very similar these two frameworks are. Pylons basically admits that it takes well founded queues from rails. But who wouldn't?


If you were to design a framework today, and you think it through, any MVC framework will smell like rails, which has hundreds of contributors, all tweeking the code base. When a populist approach takes hold, you end up with some "trueisms"


All Pylons has done, from my inspection so for, is taken those trueisms as a starting point for their framework, and now are building off that on their own direction.


Common Features between Pylons and Rails


Here is what I noticed, 24 hours into trying Pylons, as it compares to Rails:



  • File structure is similar - Rails and Pylons both create a whole bunch of files to the project folder. Pylons however has more files outside of the project's directory that are used to setup information about the egg file. Think of an egg as a ruby gem, i guess.

    Again, notice that inside the QuickWiki root folder, you have a QuickWiki folder where all your code goes into. This to me, looks like what we'd see in rails. Also, notice the models, Views(Templates) and Controller is mingling with the public folders, etc...

  • Routes - these seem similar, down to the map.connect. however, i've yet to find out if they implement Restful routing. They do seperate their controller commands by controller and RestfulController, so time will tell. Again, it's just been 24 hours. On first impression, Pylons routing actually can do a lot more, then what i've seen in rails. If this feature exists in rails, i've not seen or read about it in a year and a half. In Pylons, the first routes are the ones handled last, where as in rails, the bottom of the routes file gets executed last. Here is the example from their tutorial:

    Notice again, that last line before the return. If you entered a url "/whatever" and it doesn't exist, the last route will create the page for you, based on it being the title. That title variable is passed to the show page and saved in the DB. Perfect for wiki applications. I don't think I've seen that in rails, to date.

  • Environments - Both Pylons and Rails have development, test and production environments. In pylons it appears that the environment files are housed in the outer file system, see image above to get what i'm saying. the inner file system appears to be where you'd put most of your code for the MVC part of things. Now in part two of this post, i'm sure to have written about production deployment and the differences there. if not, screw you Lulz.

  • Error Pages/ Debugging - Both have a cool stack error printout on your browser, when you fuck up. However, Pylons is interactive and you click on these arrows to get to the right code from within your browser. You can also send Pylons an email right from the error page, if you wanted.


Differences between Rails and Pylons - initial thoughts


I know i added some variances above too, but here is a list of things that is really different between the two frameworks:



  • You are making an Egg file, not a web app. - Ok, this is my spin on the whole thing, but technically you are making a python egg that will just happen to be served through the web. In rails, we are creating a web application in ruby. Not a ruby gem, not a ruby script, a full on independent web application whose sole purpose is to be viewed through an internet browser.
    While i may be putting it too simply, it was something to get used to that when you are coding you are technically creating a python egg file that you can either, give to your friends to play around on their computer, or serve it through the web, or what have you. Maybe this has to do with the fact that you are creating a WSGI application. Read Pylons concepts here for more details.

  • Pylons needs to be running in a Python virtual environment, in order to work. What that means is you can't just call Pylons create -t MyProject willy nilly. No big deal, just something to get used to.

  • Pylons uses something similar to ActiveRecord, but in the python world it's called SQLAlchemy. From the pylons site: SQLAlchemy is a powerful Python SQL toolkit and Object Relational Mapper (ORM) that is widely used by the Python community.

  • No Migration files - All migrations are setup in the __init__.py file of the models directory. Personally, rails has it right, with it's easy to understand migration creation, in my opinion. However, Pylons isn't hard, it's just, well, more.

  • Templating Engines - Instead of ERB, they use Mako, by default. It's not that strange when learning mako, as some of the nomenclature is similar.


Conclusion


Both have their pros and cons. I don't mind Pylons, and I'm going to try and create a project in Pylons, something other then the wiki from their tutorial. I'll be bloging my way through that project, and giving you the usual uncandidness you've been accustomed to. If you want to expand your web framework knowledge past rails, Pylons is a good choice to start with, without the huge learning curve.

Friday, May 1, 2009

When in doubt... Factory it out...

Boy did i have a doozy of a day trying to get some basic tests to pass, after i added some validations to a basic rspec_scaffold. Using the barebones tests, adding the validates_presence_of and a validates_uniqueness_of both borked the test... which was fine, i expected that.


What i didn't expect was that when i commented out both validations, my create test spec method would still work. in essence, it didn't. It could have been something i did, whatever. I fixed the failing tests by simply switching to Factories, instead of fixtures, or whatever the base rspec scaffold would use in a model test.


If you are getting some weird errors, simply try to use factories instead. Try out Factory Girl by Thoughtbot for an example of one that I can say works. haven't tried too hard to get machinist to work yet, but heard good things too.

Saturday, April 25, 2009

Rails Template FTW

Boy oh boy, rails templates kick ass. I just made a template that has everything i need to start an user authenticated monthly subscription rspec app.


What's this template got that i ain't got?


Other then charisma and a good sense of style, it has


  • Restful_authentication w/ AASM && will_paginate - creates your User and Session automatically
  • Active_Merchant - sets you up for adding monthly subscription code
  • Subdomain_fu - allows for easy account creation with subdomains.
  • Testing: Rspec, Cucumber, machinist, faker, factory_girl too
  • rspec scaffold an account model to begin your journey


Rails templates are good to get you going but they are just a starting point, you still need to add certain bits of code to make stuff work, like
require 'aasm'
to your config/environment.rb file.


How to Rock the Template


Type the following into your console
rails -m http://github.com/nerbie69/rails-templates/restful_merchant_account.rb app_name_here -d postgresql
Remember that the code above will create a postgres based rails app, so supply whatever DB flag you want, mysql, couchdb etc, and replace app_name_here with whatever you want to call you app.

Wednesday, April 15, 2009

Rails Visionaries - Gems/Plugins Top Contributors

The following is a list of the people/companies whom i feel are leading the pack when it comes to the most useful gems and/or plugins. My criteria is that the gem/plugins are almost KEY to any rails app that needs them, and that this person/company has more then ONE key gem/plugin. FYI - I left out DHH, he gets enough accolades. Let's begin



  1. Technoweenie github repo - Where would a lot of rails apps be without restful_authentication and attachment_fu, just to start. When you add in Acts_as_paranoid and his work with Mephisto, we owe this dude a big thanks for making components of what we do in rails easier and more efficient.

  2. thoughtbot github repo - This company keeps pumping out hit after plugin/gem hit. In the field of testing, they help simplify our testing needs by putting out shoulda and factory girl. In the authentication field, they gave us clearance and paperclip. In the error notification field, they offer hoptoad, (which is rad).

  3. mbleigh github repo - Now mbleigh is a dude that should get mad props, and you should get to know his work, if you aren't familiar yet with him. Essential gems/plugins such as subdomain_fu and twitter_auth are just two of his current 24 projects he has on his repo. When you add acts_as_taggable_on and his ubercool uberkit (for easier form and menu creation), you realize how truly original his work is to our community.

  4. Phusion github repo - Passenger makes all production app serving easier. Back in the day, it was mongrel that made things easier... things keep evolving. However, i can't see how it could get any easier beyond Passenger, which makes setting up your slice/VPS extremely easy. And from their website they describe the Ruby Enterprise Edition as Transparently improve scalability and efficiency of Ruby on Rails web applications.

  5. Shopify github repo - If you handle anything to do with ecommerce you must bow at the generosity of the shopify folks. You have active_merchant, active_fulfillment and active_shipping. easy enough to use, powerful and well thoughtout and maintained.


Honourable Mention


There is no question to the visionary impact that these individuals have made to the rails community and furthering it's progress. In the spirit of this post however, these luminaries have given us fantastic testing apps, while this post was looking at those who have given us more then just one type of gem/plugin.



  • aslakhellesoy github repo - Cucumber is making BDD testing easier for everyone. A killer gem that makes learning testing palatable.

  • dchelimsky github repo - RSpec. enough said. (I do realize it is a team of core dev's who create this, but for clarity purposes, his name is usually at the forfront of any rspec conversation).

  • thinking_sphinx github and acts_as_ferret github - Good search plugins and gems. You are either a Ferret guy or a Sphinx guy.


Well that is the list. Enjoy

Friday, April 3, 2009

Weekend Rails Challenge #1

Thanks for participating in the first ever Weekend Rails Challenge.


The rules are simple for this challenge:
You have 48 hours to code a "For-Profit" based rails app using the twitter api. Also your app must have a colour scheme revolving around the following hex code #7C6D8A. Lastly you app Must be online and useable, hosted by yourself of course on your vps slice or node.
The challenge will run for a month and a winner will be chosen based on the app which gains the best combined score based on five different criterion.


Judging the winner



The winning app will have demonstrated the best TOTAL score of the following criteria:


  • (20%) Quality of Code - Following the rails mantra of DRY and readability, a mark will be given to you based on how well your code follows these coding principles. Usually you would test along the way but we've decided that in 48 hours that is not mandatory for this challenge.

  • (20%) Site Popularity - The site with the highest Alexa ranking at the end of the month will receive a full 20 points, 18 for the second best rank, down to 12 for the worst ranked site. 5 bonus points are rewarded for a mention in twitters sidebar menu (located below the profile of a twitter user)

  • (10%) Site Look and (10%) User Interface/Interaction - The site with the best looking and most functional user interface will gain top points in this category. Places 2nd, 3rd, and 4th will recieve 2 points less then the preceding ranking

  • (20%) Revenue made in a month - The site with the most revenue made during the month will gain top points in this category. Places 2nd, 3rd, and 4th will recieve 2 points less then the preceding ranking.

  • (20%) Most Creative Use of the given rules - An app that demonstrates the most creative and functional use of the given rules will gain top points in this category. Places 2nd, 3rd, and 4th will recieve 2 points less then the preceding ranking.




How will the scores be judged?


No idea, but i know that we participants will vote and we'll ask someone or a few people from ROR to vote on things like coding, site look and feel and creativity.


Submission Deadline:


We'll report back who ends up in the final challenge eventually, but if you want to enter, you MUST post a comment below regarding the purpose or solution you came up with for your app by 12 noon, as of you own time zone, on Saturday April 4th.



Good Luck Challengers


Best of luck and hey who knows... you could get a great money making app out of it. At worst, you made some new friendships and had a good weekend coding and learning.

Saturday, March 14, 2009

Creating a Rails Plugin - thoughts behind Active_Affiliate

I'm about to launch a new whizbang plugin. Really excited about it as i think it will add something to the Rails community and show that i have learned SOMETHING over these last 18 months.


I just wanted to document the thought process for this plugin, without talking about the code. Hopefully you find it interesting, or even helpful


Thought Process


I started with the premise that if you run a successful web app, that charges a membership/account fee, you will need some way to bring in new customers. Affiliate programs are a way to leverage the Internet Marketing initiative and your app.


There really are just two main players in the affiliate space, commission junction and Linkshare. There isn't anything wrong with these programs and chances are you'll need them too, but hosting your own affiliate program and managing it how you want, was a dream i wanted to fulfill.


Since i code in rails, and there was no solution, i created one. Here are some of the features.


  • Affiliate Signup through a route /affiliates

  • Affiliates get their own unique code

  • Primitive banner ad generator that will populate link with their code

  • Affiliate code tracking put in session variables, and saved on customer purchase, through your checkout/signup sheet.

  • Currently, paypal id's are needed so the user can get paid.

  • Reporting for both the Affiliates and App Management.


I'll be updating active_affiliate on github as features are implemented.

Thursday, March 12, 2009

Weird script/generate scaffold behaviour

As always feel free to correct me if i'm wrong, but here is some wacky behaviour i got when i used the following code to generate scaffolding from rails 2.2.2 core (i.e., no plugins or scaffolding generator plugins at all)


script/generate scaffold affiliate name:string user_id:integer


What was happening to my code was views not being found. restful paths not being found, even when i triple checked my routes file. To solve this i simply reran the code with a capital letter for the model name, as shown below.


What should the code be??


script/generate scaffold Affiliate name:string user_id:integer


Treat scaffold like every model is always CamelCase


By that i mean no matter what the name of your model is going to be always Capitalize the main words for that model. So single word models like Ass, Border, User are good. Never start with a lowercase ass, border or user.


This is just a rule i follow, as i've yet to see it let me down. It might just have been a momentary blip we all experience in our coding life, however capitalized models have never shown me that blip to date, so i'll run with it!

Monday, March 9, 2009

Rails Testing Confessions

Father, My name is pjammer and i have confession to make. I've made 4 web apps and didn't test one of them, in a rails sense.


That's right. Not one of my apps were tested using shoulda, coulda, woulda. Rspec was just a figment of someone's imagination, when i launched my apps, cause it sure wasn't in my mind's eye. Factory girl is a movie about some broad from the 60's and Object daddy just sounds creepy


Let me repent for my testing sins!!!


Father, I'm here today to repent for the sins of not testing my apps. I really want to learn


Learning about testing is like searching google for a future thought. Lots of ideas you can get out of it, but nothing that says "HERE IT IS MY SON".

This post won't help you either, but it should give others who want to make a lot of money, teaching other users how to write tests for rails, some kind of "IDEA" for a tell all book about testing.


The Big Idea


Father, why hath thou forsaken my learning? Learning Rails was easy... tonnes of help on blog posts, forums, etc... yet when it comes to LEARNING HOW TO TEST, doth hast left that chapter blank in thy bible


Here is what i think someone could make a mint from writing a book that steps a user through building tests from TIT to TAIL.


For instance:

  • What is testing and why it's important
  • There are four facets to testing
    • Functional Tests
    • Unit Tests
    • Integration Tests and
    • Fixtures
  • Take each testing facet above and step through each assertion and when to use each assertion and 5 or 6 real life examples for each.
  • Focus just on Test::Unit, Shoulda, and Machinist & Faker for Functional and Unit Testing, as well as fixtures
  • Lastly, use some cool visual tool like webrat or Selenium


Father, thank you. I will say my 10 hail mary's

In closing god would be happier with a book such as this, as less rails noobs and testing noobs would be praying for this kind of mundane nonesense. Leaving more time to fight the good fight.

Friday, February 6, 2009

My list of items to finish before the big launch.

I just thought i'd post the items that i need to finish before i launch. As i cross each one off of the list, i'll report back on how i tackled each problem. Some answers may take a whole post.


The List


  • figure out up to 7 day activation period for Accounts. Not a free trial but You have up to 7 days to activate.

  • add site for sale area.
  • Completed Ranks. Moderator roles is a feature i'll add later.
    Add forum roles to forum and make extendible if needed.

  • add user google adsense code section.

  • When new plugins are added, I'll need to create an instantiator based on the menu items the user has selected. #how to handle old members based on a new plugin being added? How do other sites handle it?

  • add body[:url] to mailer based on the current url they are on.

  • look into using AASM which creates a state for the accounts based on the presence of profile_id and then the current status of the user, as taken from paypal. (Users can cancel a monthly subscription on paypal, i need to know who is doing what)

Some of this shit may not make sense to you, however you will be able to tweek it to your exact situation.

Sunday, January 25, 2009

How to deploy when Capistrano doesn't work for you.

What happens when Capistrano just doesn't work for you?

Ok, maybe i'm the only one with that problem, but i've tried on three different server providers, linode, gogrid and slicehost. All had the same problem, somehow, someway my user privleges were f!@#cking it up.


When a tutorial i've trusted tells me to put my directory to chown www-data, well, i am going to do that. In order to do this i need to sudo everything, thanks to ubuntu, and it's a best practice i can wrap my feeble mind around.


How to deploy a rails app when Capistrano just ain't working for you.


I've not been able to find one source on the net that showed me simply how to deploy a web app using just git, and ssh. So i'm open to better ways, however, i've tested this way for the last 3 weeks and am pretty happy with it.


Prerequisites


You are using

  • GIT locally and on your server
  • a full Rails setup (I'm using passanger)
  • a server that hosts both your git repository and your app
  • you've setup both your app and git repository on that server box too

  • You are also using www-data as the group and user who "owns" the app on the server.
    That is just too much shit to talk about right now.


The code below walks you through what to do AFTER your initial setup of your server and app environment.



  • On my laptop:

  • Make the changes to your app, when every test passes and when you are ready to go to production do the following:



    • git status # on my machine changes appear in red.

    • git add . # notice the dot after the add

    • git status # if you see anything in red that should also be included use the second git commit line below

    • git commit -m "Add your message about what your committing here." #most of the time use this

    • git commit -a -m "Added all files including untracked ones" # Again only use this one if there are files that appear in red and should also be included in your commit.

    • git push # pushes your code to your server.




  • SSH to server, all these commands are done from your server:


    • cd /var/your/directory/to/your/app # e.g, /var/www/myapp

    • sudo git pull #pulls all of your latest changes and merges them into your app. see troubleshooting if something f@#cks up.

    • sudo rake db:migrate RAILS_ENV="production" # and any other things you need to do, like start ferret or whatever.

    • cd ../ # back out of this directory

    • sudo chown -R www-data:www-data myapp #notice that we are changing ownership of the whole myapp directory and everything below it. Passanger loves this.

    • cd myapp/

    • sudo touch tmp/restart.txt # how to restart passanger




End


Well i spent 2 or 3 days easily, 4 - 8 hours at a time trying to make capistrano work. The process above takes 3 minutes. Someone else can do the math, but in order for this way to be less efficient, i'd have to do some 300 commits before i regret not having capistrano. One day i'll need it to deploy to 100 servers or something but for now, i can live with the process above.

Wednesday, January 21, 2009

theme_support and formatted routes (rss feeds)

Today I was trying to get my web app to allow subdomains to provide an rss feed. it didn't work.



I'll be posting a solution when one is found, however, i'm hoping this wasn't pebkac again.



Solution


In your controller, where you are making the rss call, you must render layout false. Here is an example:

format.rss { render :layout => false }
I'll file this one under the learn something new, that is easy, everyday column.


After some investigation, it appears that theme_support plugin doesn't support themed rss feeds, when you enter them in the head section of an html page. I'm working to allow this in the plugin.

Saturday, January 10, 2009

passenger and the case of the non-redirecting account. -solved cause i'm dumb.......

Let me explain what is going on here. In my code I want the user to create an account (from www.domain.com) and then, upon successful creation of the account, I want them to redirect to the new account's url, at say account.domain.com.


Redirect doesn't happen in Production


I'm using Passenger and Apache on a ubuntu server.


On my dev box: Mongrel from the rails app, the usual script/server stuff


So on dev, it works fine. I get redirect with reckless abandon.

In production, a different story. I get the following error (using safari, yet to try with other browsers...).Safari can’t connect to the server.
Safari can’t open the page “http://www.example69.com/accounts” because it could not connect to the server “www.example69.com”.

Why me? I should say, I can type my new url into the browser, no problem. it works fine, but it's not what I want my user's to have to do.


Did you solve this?


Embarrassingly I had a link to localhost:3000 as my redirect. Ignore this post. it's left as a reminder when i get too fucking cocky.... as a mark on my pride.

Tuesday, December 16, 2008

Rails Engines are awesome!!!!

Some of my loyal fans may be shocked to know that i just tried the Rails Engines plugin. Officially titled engines plugin on github.


So easy, and exactly as advertised


Sometimes, try as we may, things aren't always as advertised in this community of ours. So it is a good when things go exactly as planned


Instructions on using the plugin are well written in the README, so i won't bore you with those details, but if you have ever wanted to make a plugin that had the same familiar structure as your rails app', then this is for you. All you need to do is create a plugin and then add the same app directory structure in the root folder of the plugin.


Predictions


Theoretically you can make all of your controller, models and views as plugins, making your app act almost like it's own SAAS appliance. If you have a generator style'd plugin, there is no reason not to use engines. Less coding for you, the plugin creator.


Examples of Hot Rails Engines Action (HREA?)


In fact, i just put the finishing touches on my fork of the rails stat plugin, that was purely a generator script, basically. Now in my forked version, the engines plugin takes care of generating static code within an app. And that is pretty frickin cool.

Saturday, December 13, 2008

Working with Generators in Rails - Lessons Learned the hard way.

I'm updating a plugin that works in Rails 2.2.2 development, yet borks in a production site using 2.1.0.

undefined method `render' for # Rails::Generator::Commands::Create:0x7fdf1caaa2c8


right now, Here is what the problem was


in my generator script i had the usual code
m.template "app/views/rail_stat/hits.rhtml", "app/views/rail_stat/hits.rhtml"
m.template "app/views/rail_stat/lang.rhtml", "app/views/rail_stat/lang.rhtml"

Now inside of hits.rhtml is the following line
< %= render :partial => 'menu' % >

For some reason the render part fudges everything up. if i delete that line, the files go through with no problem.


Solution


When generating erb templates, the Rails::Generator needs to use an extra percentage sign whenever you call specific erb calls. For instance, i only had used < %= render :partial => 'menu' % > but i should have used < %%= render :partial => 'menu' % >
Again, notice the extra % percentage sign in the second code bit. I'm sure there may be a better reason but the second % sign acts almost as a buffer and tells m.template to print the erb code in the new file? Again, that may be too simplistic of an answer, but that is what it seems like to me.

Tuesday, December 9, 2008

Finally. Theme_Support fully Working in Rails 2.2.2

I feel like singing. That is how happy i am.


Theme_support plugin for rails is fully working in Rails 2.2.2


I'll work with jystewart from github to get the fix onto his version, as that is what i got to work. Here is the link to Theme_support on github. Alegria!

Friday, December 5, 2008

Transferring an existing app to a new server

Let the good times roll gents. Rick Okasik and the cars once sang that song about this exact moment in time. The day I transferred my existing ruby on rails site from a shared host to slicehost.


Preamble - Reasons why, etc...


My shared hosting account at a2 has come to an end. They have been having a couple of days worth of outages here and there. Nothing too bad, usual disk failure kinds of stuff, but what really got my goat was this. A bug in cpanel that didn't allow the mongrel server to restart. So my site would be down for an eon, because they restarted the server or apache or something (never got straight answers). Now i'm a patient guy, but in terms of my website as a business, they were messing with my livelyhood. Good intentions or not, it sucked for that reason.


So the time has come to grow up and move to slicehost. I've tried Linode but i prefer slicehost. Both really offer the same principle offerings and are strictly/typically linux based servers, so i liked these two. But for some reason, slicehost resonated more with me. Just a thing i have, no fault of anyones.


Steps involved in transferring an existing app to a new server


I'll be chronicling my journey through transferring a rails app from a shared host to a VPS like slicehost. Here are the steps I took to move the server:

  1. Backed up MySQL database on old server

  2. Ftp'd backup db to new server

  3. Copied app code to new server

  4. Imported DB onto new server

  5. Fixed app settings to let it run properly, such as action mailer, etc.

  6. Updated DNS records to reflect the switch.


For the record, i already have a working passanger/mail system/rails stack on slicehost. I will chronicle what I needed to do to get this to work. However, your mileage may vary and if you screw up anything, even because of my instructions, i'm sorry, but that's on you and i won't and can't be held responsible. You've been warned.


Good, got that crap out of the way, on with the show.


Export Mysql database from old server


I followed this Slicehost article on exporting and importing db's. It was pretty easy so far.


Zip code on OLD server


As i'm using the command line for all/most of this transfer, a great resource for zipping files was About.com. Although not as sexy to use, it had all i needed. I used the following commands:

zip -r app_new app -x \*.log

Notice the -x which will exclude your stupidly huge log files. I need to find a better way to manage them.

By the way i went from 40mb zip file with logs to 10.5mb zip file. need i say more

FTP code and .sql file to New Server


No explanation really needed here. I used ftp from old server to my desktop and then i used sftp onto new server at slicehost. Your mileage may vary, but you get the idea.


Unzip code into new /var/sites/ directory


I unzipped the code into a web-applicaton chmod'd directory.
unzip app.zip


Import DB.sql file into the NEW Server


The Slicehost article on exporting and importing db's again came in handy here. So easy, so good.


Setup your new DB user


I ended up creating a new user, just to be safe. Probably no need to do this, as you can keep the same one from your old server, but just in case. I just followed this Slicehost article on creating Mysql users. Grant All privleges, as he shows in the article.


install all your outstanding gems


Since i forgot which gems i need, and I am not ready to upgrade this app to 2.2.2 yet, as it's in rails 2.0.2, I need to go to the old server, and pull off all the gems i used, and reinstall them on the NEW server. Once this is done, we can setup the config files for actionmailer and the db itself.

Well it looks like it's the old rmagick gem that was the troublsome one. Thanks to enrailed.net for helping me out with this one. It's weird to me how i followed the same steps using aptitude and I got an error, but if i use apt-get, i was fine... whatever eh! Oh and gem install rails -v 2.0.2 just hung there, so i said screw it, and i'm going to go with the one i have on there 2.1.2.

Lastly for all UBUNTU Hardy users that don't know.... update your ruby gems. the POS that is shipped with that ubuntu version will disappoint you, if it hasn't already. Thanks to Mike's post here at a fresh cup blog you'll find out how more. Simply put, just run
sudo gem install rubygems-update
sudo update_rubygems



Update Config and database files


so you'll need to update anything in your config/environment.rb file that was server specific, such as actionmailer settings. Also, make sure your config/database.yml file reflects your NEW database.


Update your server settings


I, like most of the free rails world, are now using passanger to serve our app. If you aren't, run, don't walk, to the nearest passanger downloading station and fricking do it! Mongrel's time has passed, much like zed shaw's rants. It meets my needs, that is for sure.

I added the following code to passanger:

ServerName sitename.com
ServerAlias www.sitename.com
DocumentRoot /var/rails/sitename/public



Since i have two other sites on my slice, i need to make sure that the NameVirtualHost *.80 is only added to the "first" site or in other words, only once.

The best passanger, slice from scratch tutorial is Part One and Two of sys admin chronicles.

Change your DNS records on your slice and with your Registrar


You'll need to change where your DNS is pointed, i.e., from the OLD server to the NEW one. Slicehost makes that part easy with their DNS manager. For the registrar part, you need to go to the registrar of record, in order to point it to the new settings. I change the registrar's record first, then i change mine on slicehost. But again, that's what i've done.


Restart the App and you are done


I think that is it friends. You should have the same app as you had before working on a new server. This wasn't rocket-science but it was a good list of 'things you need to do' when converting over to a new server.


To do...


I'll post how i got a multi-website postfix configuration going on my slice. I've yet to find an easy tutorial that works... but i'm looking. Thanks everyone. The good times are rolling again.

Wednesday, December 3, 2008

Theme Support plugin update for Rails 2.2- Part 2.

So i have tried my damnedest to make this work. I get an error as follows:

undefined method `compute_public_path' for #
So, for some reason in theme support i am getting this crazy error, where in Rails 2.0.2 i did not, and in another project, which was Rails 2.1.2 using the "old" theme support, i did not get either


Possible Solution (TBD)

It appears that the compute_public_path method is now a private method of the class AssetTag in the module ActionView::Helpers::AssetTagHelpers.

What I still need to figure out


How in the hell do i link this 'sub class' AssetTag to the Module line in the rhtml_helpers.rb file in theme_support? I've tried various configurations to no avail. Who out there is a plugin god and can help out?

Tuesday, December 2, 2008

Theme Support plugin update for Rails 2.2

Commentary: This plugin always has to be updated after every version of a rails upgrade? I don't know why that is however? Perhaps it's the most unluckiest of plugins? carma? something... but like a trooper, it keeps on licking and ticking.



If you are using theme support and have recently upgraded your app to 2.2, you'll need to fix this plugin before you get anywhere. luckily jystewart from github has patched the plugin to work with 2.2. from what i see it may even fix it for a while, so that finally we won't have to keep patching this thing.



URL: http://github.com/jystewart/theme_support/tree/master

Saturday, November 29, 2008

Updating Rails app from 2.0.2 to 2.2.2

Ahh the fun begins. In this post you will find the 'gotchas' I had with updating an existing established app from rails version 2.0.2 to the new version of 2.2.2.


Cache_template_extensions Error


Here is the partial stack error


/Users/nerb/.gem/ruby/1.8/gems/rails-2.2.2/lib/initializer.rb:530:in `send': undefined method `cache_template_extensions=' for ActionView::Base:Class (NoMethodError)


Solution! - There was mention of an error at line 15 of my environment.rb file. I went to the environments/development.rb and deleted the line
config.action_view.cache_template_extensions = false I read on the interweb that this cache_template_extensions no longer is used or is has been deleted.


Now maybe the time to update Plugins.


As a public service, I wonder if now is the time to update your plugins, if it's been awhile. Some may never change (Acts_as_tree), but some change fairly rapidly (Restful_authentication).


For Restful Authentication, I know there is a new password feature that doesn't jive with the old passwords. However, since I also need to update this plugin, I wonder if it's better to scrap the --old-passsword flag and investigate why the new way is better? Could it be that I may change all of the current user's passwords on my site? Only if there is a dang good reason. A dang good one.