768x90 Getting Online Shouldn't be Tough- $7.49 .com Domains at Go Daddy

Deployment Tutorial Using FastCGI (.fcgi) for Rails Application

FastCGI Process

I just want share my experience when my first time deploy rails application using FastCGI. Here's step by step of installation fastCGI for your rails application.


preparation offline

  • Already have Database and hosting server in 1 package with linux OS
  • Already Complete ruby on rails application
  • export your database to file or dump your database to external file.
  • Go to your appz_name/config/environment.rb. You need to uncomment the following line to confirm you're in production mode:
ENV['RAILS_ENV'] ||= 'production'
  • Modify your appz_name/public/.htaccess file by changing some parts to the following below:
# General Apache options
#AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
...
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
#if you see RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
#in your file, change it to like below
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

  • Set up your database in your hosting or db server online, create 3 databases, after that match it to appz_name/config/database.yml if you found difference setting, fix it. Your database.yml must be the same like your setting in database server including database password, username, database name.
  • Now, the last step, go to appz_name/public you will see 3 files with named dispatch*.*. Open them and change their first line to be
#!/usr/local/bin/ruby
  • edit your routes.rb in appz_name/config/and uncomment :
map.connect '', :controller => "your_main_controller_name"
  • delete or rename your index.html in appz_name/public
  • Attach or archive your app project folder in zip or tar.tgz.


preparation online


  • use your putty to access your shell console account of your hosting. After logged, Go to your /home/username upload your attached app project folder to this area then extract it.
  • your will get your project rails folder from your extracted file.
  • Back up your existed public_html :
mv ~/public_html ~/public_html_backup
  • I forget to tell you the most important thing, that is you must chmod 755 dispatch*.* in your /home/username/appz_name/public
  • after that back to /home/username and run it:
ln -s ~/yourapp/public ~/public_html

Done !!! If you did all those steps correctly you will not see Application Error message in your browser. Have nice try and good luck.

About Yacobus Reinhart

I am very passionated and challenged to user friendly, clean and elegant application (web & desktop).  There's no thing that can satisfy me unless I have to defeat all problems in the project and deliver it perfectly.
I am standalone developer, analyst and software consultant both desktop and web base, My strong foundations are Adobe air and Flex 3 and 4, Ruby on Rails 2.4x and 3.x, CakePHP and JQuery since 2007.

 My background experiences like working in great companies, bachelor degree Informatics Engineering and unique client's cases more and more place me on solid skills in software world.
Please feel free to contact me on gmail or business mail or participating in my blog for any discussion, questions or idea, i will be freely to assists you with all my best.

Best Regards,

yacobus@reinhartlab.com (business) or yacobus.reinhart@gmail.com (home)

www.twitter.com/yreinhart

http://id.linkedin.com/pub/yacobus-reinhart/1b/aa5/220

Active Record - Session 1


Ruby is not Unidentified Programing Object, but it is Universal Programing Object


As we know that rails is built by MVC design. Let we understand MVC (Model-View-Controller) instantly.



  • Model contains all information of operations or tasks that corresponding to process your database like CREATING, READING, DESTROYING, and UPDATING your database. Transaction Support and Store Procedure are created in Model too. But Transaction Object is in Controller.

  • View, it's all about display of your information or output of process. Your webdesign, information that want be displayed to realworld or user and output of data process are managed in View files.

  • Controller is brain of everything. Like the name, it controlls all process and also filter for all information of input or output. example before data displaying to realworld/ your user, it should pass controller first .

So where is Active Record in Ruby on Rails? it is in model. Active Record is Ruby Library that allows your Ruby programs to transmit data and commands to and from various data stores,whic are usually relational database. If you dont have Active Record, dont go away. Calm down and type this gem install activerecord to your ruby cmd. Let's implement it.


Create a Record


email = Email.new
email.username = "teapoci"
email.password = "myfav_tea"
email.customer_name ="Ariand Handsome"
email.customer_country = "Indonesia"
email.save

The generated SQL would be

INSERT INTO emails ('username', 'password', 'customer_name') VALUES ('teapoci', 'myfav_tea', 'Ariand Handsome')



Reading a Record

all_email = Email.find(:all)
first_email = Email.find(:first)
email_by_id = Email.find(10)

The generated SQL would be

SELECT * FROM emails;
SELECT * FROM emails LIMIT 1;
SELECT * FROM emails WHERE id = 10;


How to use :conditions

Email.find(:all, :conditions => ["customer_country = ?", "Indonesia"] )
Email.find(:all, :conditions => [:customer_country => "Indonesia" )
Email.find(:all, :conditions => "customer_country => 'Indonesia' "

The generated SQL would be

SELECT * FROM Emails WHERE customer_country = 'Indonesia'

-------------------------
---------------------------------------------------------------------------

Email.find(:all, :conditions => ["customer_name LIKE ? AND customer_country != ?", "%ar%", "Indonesia"] )

The generated SQL would be

SELECT * FROM emails WHERE
customer_country LIKE '%ar%' AND customer_country NOT IN ('Indonesia');


How to use :include

:include is like join table in SQL, it will look like nested hash of ruby in its script.



class Customer < ActiveRecord::Base

has_many :invoices

end



class Invoice < ActiveRecord::Base

belongs_to :payment

end



class Payment < ActiveRecord::Base

belongs_to :processor

end



class Processor < ActiveRecord::Base

end



Customer.find(:all. :include => { :invoices => {:payments => {:processor = > {} } } }, :conditions => ["processor.name != ?", "paypal"])





The generated SQL would be

SELECT * FROM customers
LEFT OUTER JOIN invoices ON customer.id = invoices.customer_id
LEFT OUTER JOIN payments ON invoices.payments_id = payments.id
LEFT OUTER JOIN processors ON payments.processor_id = processor.id
WHERE processors.name NOT IN ('paypal');


How to use :order

Costumer.find(:all, :order => "created_on DESC, last_name, first_name")

The generated SQL would be

SELECT * FROM customers ORDER BY created_on DESC, last_name, first_name


How to use :select

Costumer.find(:all, :select => "customers.last_name, 'family name' " )

The generated SQL would be

SELECT last_name AS 'family name' FROM customers;


How to use :group

Costumer.find(:all, :group => "state" )

The generated SQL would be

SELECT * FROM customers GROUP BY state;



How to use :joins

Costumer.find(:all, :joins => "LEFT JOIN invoices ON customers.id = invoices.customer" )

The generated SQL would be

SELECT * FROM customers LEFT JOIN invoices ON customers.id = invoices.customer_id


How to use :from

Costumer.find(:all, :group => "state" )

The generated SQL would be

SELECT * FROM customers GROUP BY state;


to be continued....


Portable Ruby - As Easy as Ruby did

Hmm.... Ruby is very interesting programing language. I am one of thousands ruby fanatics. I am mobile person, when i am in cyber cafe and want finish my ruby job, i have to install ruby, gems and also database, very tired of work and full wasting time. Let's fight it and make your self more confidence with ruby where ever you are.

"Ruby really made me stronger..." - Bruce Lee - 1970



Let see step by step how to install Portable Ruby to your FlashDisk or USB Drive.
  1. You should have a downloaded ruby installation first. I prefer to use one-click-installer , but dont install it, just download it 'till finish.
  2. Let's Download RubyPortable Template and extract it to your USB Drive or Flashdisk. I advice you to use flashdisk or any mobile drive with space more than 512 MB. Because Ruby will take space 80MB.


  3. Taking from the picture above. Let install one-click-installer to J:/RubyPortable/App/ruby/ , if you see alert message to remove folder ruby, choose 'Yes'.
  4. Honestly, at this way you can use portable ruby. If you want make ruby on rails, you should update gem, you can install also sql portable to support your work or use external database like in webhosting you have. Let's run J:/RubyPortable/RubyPortable.exe and you will get this (if not works, go to step 5)


  5. But because RubyPortable allows saving a lot settings (one or all of them at once):
    - One or more registry keys
    - One or more settings directories
    - One or more settings files
    You can go to the next step.
  6. we Now, let we install plugin for running our RubyPortable and sCite, you should download the following files: NullSoft Installer, HM NIS EDIT(script editor for installer), NewAdvSplash plug-in, Registry plug-in, FindProc plug-in
  7. Install NullSoft Installer and HM NIS EDIT in any folders of your windows.
  8. After you download NewAdvSplash in zip file. Find file with name - filenewadvsplash.dll and copy it to folder plugin where you installed NSIS is.
  9. Extract Registry plug-in and you will get fold desktop, and run install.exe
  10. Now the last step extract and copy FindProcDLL.dll to the NSIS plugins directory.
  11. After you complete all those steps, open your HM NIS editor and open the file RubyPortable.nsi that located in folder J:\RubyPortable\Other\RubyPortableSource.
  12. Closer to the top you will see "Define constants " you can set as you want. If you want this as a default setting, you can compile it as CTRL+F9


  13. Now Your Portable Ruby can be used. You can install rails or gem. To edit ruby file you can use Scite Or Notepad :p
  14. For more information : In most cases, all you would need to do is update the constant definitions at the top of the script. Based on these values, the created launcher can make changes to the system registry or settings, launch the target program, and restore the registry and settings to their original values when the program closes.

    I prefer to avoid changing the registry or system settings at all costs so as not to cause any problems on the host PC should problems arise. Our problem then becomes, how do we open a command window with the PATH environment variable correctly set when the PATH is a value maintained in the Windows Registry.

    A simple option would be to set the value of the constant "EXE" in the script to reference a file named "bin\ruby.cmd". This file doesn't exist in the Ruby distribution but we could create one that then opens a new command window with arguments for setting the PATH. We can also go ahead and update our script to perform the same action. Here is the updated entry in RubyPortable.nsi (line 395) which will do that.

ExecWait "$SYSDIR\cmd.exe /K set PATH=$EXEDIR\App\${APP}\bin;%PATH%"



References:
http://ruby.about.com/od/resources/ss/portable_ruby.htm
http://portableapps.com/node/2022

Portable SQL - Compatible with any mobile storage

Laptop is not a small stuff, you need something that is smaller and demulcent your self. I think flashdisk is nice storage to save many of applications and data. But how if you face with big data like your database or webhost? how much money you spend to buy hosting for uploading your data there? or is it possible to finish your application that support database but you dont have database there? dont you think that portability is the right answer for you, programmer, who is very mobile?

Server2Go maybe can help you in this problem. Server2Go has all you need to get your Webapplication running

  • Apache 1.3.x, 2.0.x and 2.2.x (V1.6.0 off Server2Go or greater)
  • PHP 5.2.x with a lot of Extensions. Downgrade packages to 4.4.x and 5.0.x available)
  • MySQL 5 support
  • Perl 5.8 with a lot of CPAN modules integrated
download here

 
powered by Blogger