Friday 30 November 2012

Hosting Rails app : uhurucloud.com

I'm great fan of Heroku : ease with which it let you deploy your app.
In a quick minute you can set your app up and running. There are other many app providers out there and recently i come across another one: uhurucloud.com. 
It let you deploy your app without the need of adding/committing in any git repo.(git add .. git commit -m..) .
It's very easy to deploy RoR app on uhurucloud in just two step: 1) Make your app. 2) run vmcu PUSH command.

 I am working on my online resume. And i need space to upload my project list.  Currently I'm in a mid of development and not yet completed it but the work so far can be seen here.

Here is a quick step by step tutorial on deploying your app on uhurucloud.com without using any extra gem(capistrano) or pulling/pushing any git repository.


1) Install uruhu gem :  vmcu


2) Select target service

3) login into vmcu
             3.1) Get one time token
                                   Go to your uruhu cloud dashboard click the icon next to your instance name.
                                 copy the token so generated upon the screen.

3.2) Now login with your username and your one time token you just copied.




 4) Set cloud team which is nothing but the instance you created on uhuru.
I made with name "sahilsk" .


Push your app into the cloud

5) Change directory to your app root folder
    cd  /path/to/rails/app/root

5) vcmu push
You are now all ready to push your app into the cloud.
uhuru will automatically detect your application language.
It'll ask you few basic questions.

$ vmcu push
Would you like to deploy from the current directory? [Yn]: y
Application Name: portfolio
Detected a Rails Application, is this correct? [Yn]: y
Application Deployed URL [portfolio.uhurucloud.com]: sahilsk.uhurucloud.com
Memory reservation (128M, 256M, 512M, 1G, 2G) [256M]: 512M
How many instances? [1]:
Create services to bind to 'portfolio'? [yN]: y
1: mongodb
2: mssql
3: mysql
4: postgresql
5: rabbitmq
6: redis
7: uhurufs
What kind of service?: 3
Specify the name of the service [mysql-dcf11]:
Create another? [yN]: n
Would you like to save this configuration? [yN]: y
Manifest written to manifest.yml.
Creating Application: OK
Creating Service [mysql-dcf11]: OK
Binding Service [mysql-dcf11]: OK
Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (1M): OK
Push Status: OK

Staging Application 'portfolio': OK

Starting Application 'portfolio': OK

You are not all set.

open the application deployed url:  sahilsk.uhurucloud.com
YOu can see your application up and running.


Hurdles:
  I was using rails app 3.x. So, many a times after push operation my app was getting syntax error.
Problem was the use of new hash-key pair style inside session_store.rb and wrap_parameters.rb.
key:  value
I changed them to old school style.
:key=> value

then i re-run vmcu push. It will not ask you to fill the parameteres again if you had choosen to remember the configuration during the first push command .
After that everything works as expected.


References:
command line deployement : 
 http://support.uhurusoftware.com/entries/21454287-deploying-and-managing-apps-with-command-line

Getting one time token: 
http://support.uhurusoftware.com/entries/21595322-the-uhuru-appcloud-web-manager-getting-a-token

Monday 26 November 2012

Store ID's in has_many or habtm associated tables

In has_many or habtm association we sometime need to store array of id's.
So, this is how we do it.

table : Projects,  :Categories
Model: Project, Category

html form

    = f.select :category_ids, Category.all.collect{|p| [p.name, p.id]},{:include_blank => false, :prompt=>"select catgory" }, :multiple=>true



And in the controller maintain your normal flow.


def create
    if params
      @project = Project.create( params[:project])
      #@project.categories << params[:project][:category_ids]
      if @project.save
        flash[:success] = "Project created successfully"
        redirect_to :action=>"list"
        return
      else
        @project.screenshot = nil
        params[:project][:screenshot] = nil
        flash[:error] = @project.errors
      end
    end
    render :action=>"new"
end