Monday, October 15, 2012

Find type of the request in controller

Is there any way to find the type of request in controller ?

 Yes.

What we do in routes.rb is , define the type of request to particular action .

But What If we want to find out the type of request in controller .


if request.get?
   logger.info "Request is GET"
elsif request.post?
   logger.info "Request is POST"
elsif request.xhr?
   logger.info "Request is AJAX"
end


Thursday, October 11, 2012

Ajax Request in Ruby On Rails (UJS)



Many programmer uses jquery to catch click event and do $.get or $.post to access the server and print the response in a required div.

But there is a handy way to do ajax request using UJS provided by Rails .

Let us take an example of flipkart "add to wish list" event. So In flipkart.com when you click add to wish list , the item will be added in your wishlist .

This can be easily achieved in three easy steps.
Now lets see how to do that in rails using UJS

Step 1:
In view(show.haml.html) your may have
  
= link_to "Add to wishlist" , wish_list_path(@product) ,:id => "wish_list_link" 


Now we make it as ajax request by adding :remote => true
  
= link_to "Add to wishlist" , wish_list_path(@product) ,:id => "wish_list_link"  , 
:remote => true

Step 2:
Now in controller
    
    def wish_list
      #adding wish list 
      respond_to do |format|
         format.js #This line is important
       end
    end 
    


Step 3:
Now create a file named wish_list.js.erb
  
    $("#wish_list_link").html(''added to wishlist");
     # Lets say you want to render a partial .
    $("#wish_list_linkt").html('<%= escape_javascript(render :partial => "wish_list" , :locals => { :product => @product})%>');


Step 4(optional):
You can use jquery to show the loading part while server is responding
  
   $("#wish_list_link").live("click",function(){
        #show_loading_img
   })


...and that's it.

Monday, July 2, 2012

Rubber + EC2 + Rails + Oracle + nginx + Passenger



Deploying rails app into EC2 using Rubber
=================================

Step 1 
------
Get the key from aws and store it in ~/.ec2 folder  

         chmod 400 keyname

Generate the publickey     

         ssh-keygen -y -f keyname > keyname.pub

Step 2
------
Add rubber gem in your gemfile

        gem rubber

and do 

         bundle install

Step 3
------
Now do vulcanize. Am using nginx and passenger 

        rails g vulcanize minimal_passenger_nginx

Step 4
--------
Now edit following fields in config/rubber/rubber.yml

       access key
       secret access key
       account name
       app name
       app user
       image id
       image type

Step 5 : 
--------
Deploy Part :
  
       cap rubber:create
       cap rubber:bootstrap 
       cap deploy

If you are using oracle instant client set the environment variable in server and then do 'cap deploy'


Here is the way to bypass fingerprint authentication prompt : 
add these two lines in deploy script. 

ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "id_rsa")] 
set :deploy_to, "your_deploy_folder"

 


          



   

Monday, March 19, 2012

Follow Me

         This post is all about google reader.If you are a regular blog reader you might know about google reader tool.If you dont know about that you can continue reading.

 
 
Roughly am following 50 blogs.So whenever some one posts, google reader updates automatically and fetch the posts in unread items so that I can read all posts in a single window.

So if you follow my blog , you don't have to come to my site whenever I post new one. It will get updated in your reader view.

You can import subscribed blogs from your friends also.Say if you want to follow blogs that whatever am following, you can easily import my blogs list from me.For that I have to export my blog list from reader settings.It will give you the OPML file which you can easily import it in your reader settings.


If you need my blogs list just ping me to amicable.ad@gmail.com.I will send you OPML file '.
 



Tuesday, March 13, 2012

CS Encounter Specialists

     I used to play bomber man, mario in my childhood  but not much because they asked 10 rupee for half an hour which i cudnt afford that time . In my UG i got a PC from my brother and started playing small games slowly. My brother used to play AOE when he was in holidays . 

     In PG first year I didnt have much time to play computer games because of tight class schedule and Interactions(need a seperate post to explain it).  I started playing AOE with Gobinath(my classmate) in 2nd sem holidays. we played day night in the whole vacation. (But we cudnt beat hardest computer player)  .

    There comes my third sem when i became a hardcore gamer.I started playing counter strike with my friends. That was the days that will "never-come-back" . We go to class and come back at evening and start the server. Usually the server started by my friend "The One" . We connected our laptops by wifi and  I had only desktop so i always borrowed someone laptops and played from that .We played daily till 2 am .  Roughly there were 12 to 15 players. 

    My nick name in cs was AD-58 . And there were other friends also had different names called "The One,Striker,Dabaang,Kaal,Drax,Chopper,Maahkaal,Its me,kats,GBH,Feel The Heat". Others had there own names like "gobi,parthi,prabha,bishwa,shambu,siva". I always used to play in Terrorist team and CT team had led by "The One".  We as a beginners only played snow map for a long time.Because its small and no need to buy weapons(some doesnt know how to buy weapons) . 

    One day we had a match with our seniors and got screwed like anything. So after that we never had match with seniors.In the middle of third semester we connected LAN and started playing well and got a feeling like we are no more beginners.There was a CS competition in college arranged by some btech guys.So we also registered for that and it was a knockout game.A group of five people(Who plays well among my classmates )including me  went there and knocked out in first round itself.

     I didnt play much AOE in my third semester cos only me and Gobi knows to play AOE. "The One" also knows little bit of AOE but he said it ll consume more time if he starts playing. In 4th sem Kats and Chopper started playing AOE with us.So if there was no CS ,we play AOE .

   In fifth sem we changed our hostel so no LAN and it was a placement time.

Specialists : 
      The One - Plays CS very well and got a good hand in maverick
      Kaal - Next to The One . He plays well if he has a good team mate.
      Its me ,Kats & MahaKaal - Experts in ShotGuns
      Dabaang - He was always there to get a headshot from me :P
      Parthi and Gobi - Good Snipers and campers
      Shambu,Bishwa,GBH - good in fy_snow
      Prabha - Moderate
      Striker - No one knows how he plays
      Feel The Heat - One Flash is enough to kill him
      Siva  - You can kill him with a knife
P.S 
The One - Ankit
Chopper- Gopi J
Drax - Sudeep
Kaal - Pratik
Dabaang - Piyush
MahaKaal- Sunil
Its Me- Naveen
Kats- Kathir   
GBH - Gayki   
Striker - Manoj
Feel The Heat - Ashok