Wednesday, June 20, 2012

Ajax request via javascript

Hello Rubies,
      Have you tried AJAX request via javascript? Lets see the eg.

<script type="text/javascript">

  // Ajax without update parameter:
  function ajax_request(id){
    window._token = '<%= form_authenticity_token %>';
    var url = '/controller/action';
    var pars = 'id=' + id + '&authenticity_token=' + window._token;
    var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: showFailure(), onSuccess: showSuccess() });
  }

  // Ajax with update parameter:
  function ajax_update_request(id){
    window._token = '<%= form_authenticity_token %>';
    var url = '/controller/action';
    var pars = 'id=' + id + '&authenticity_token=' + window._token;
    var myAjax = new Ajax.Updater('update_div_id', url, {method: 'get', parameters: pars, onFailure: showFailure(), onSuccess: showSuccess()});
  }

  function showSuccess(){
  }

  function showFailure(){
  }

</script>

Tuesday, June 19, 2012

Disable the link in rails via css or javascript

Hello Rubies,
      We have facility to disabled the link in rails 3 using :disable_with => 'Blah...'. But what about rails lowest version? We have one of the two possible option.

Either use:
1. <a href="javascript:;"> blah blah </a>
or
2. in css define
 .disabled_link{
   cursor: default;
   pointer-events: none
;
 }
<a class='disabled_link'> blah blah </a>

Friday, June 15, 2012

Implement tab side out

Hello Guys,
      To implement tab slide out along with you application use the below code.


Download 2 javascript files:
1. jquery.min.js
2. tabSlideOut.v1.3.js


In your html page simply add below code.


<html>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
    <script src="http://www.building58.com/examples/js/jquery.tabSlideOut.v1.3.js"></script>
  </head>
 
  <body>
    <script type="text/javascript">
      $(function(){
       jQuery('.slide-out-div').tabSlideOut({
 
         tabHandle: '.handle', //class of the element that will become your tab
         pathToTabImage: 'http://www.building58.com/examples/images/contact_tab.gif',
         //path to the image for the tab //Optionally can be set using css
         imageHeight: '190px', //height of tab image           //Optionally can be set using css
         imageWidth: '59px', //width of tab image            //Optionally can be set using css
         tabLocation: 'left', //side of screen where tab lives, top, right, bottom, or left
         speed: 300, //speed of animation
         action: 'click', //options: 'click' or 'hover', action to trigger animation
         topPos: '100px', //position from the top/ use if tabLocation is left or right
         leftPos: '20px', //position from left/ use if tabLocation is bottom or top
         fixedPosition: false //options: true makes it stick(fixed position) on scroll
       });
 
      });

     jQuery.noConflict(); // use this when prototype will be conflict with jquery.
 
    </script>

    <style type="text/css">
     
      .slide-out-div {
          padding: 20px;
          width: 250px;
          background: #ccc;
          border: 1px solid #29216d;
      }
    </style>

    <div class="slide-out-div">
      <a class="handle" href="javascript:;">Content</a>
      <h3>Contact Us</h3>
      <p>
        Click on here to contact us..blah..blah..
      </p>
    </div>
  </body>

</html>

Monday, June 11, 2012

Concat string via MY SQL & PSQL

Hey guys,
      Do you know there is little bit difference to concat the string  under MY SQL & PSQL?

mysql:

update posts set title = concat(title, 'Hey')

psql:

update posts set title = title || 'Hey'


Schedule cron job on linux

Hello Guys,
   Set cron job on linux to invoke at every 1 minute or daily base.

on command prompt:

crontab -e

add below lines

For every 1 minute:

 */1 * * * * cd /home/user/application_path && /home/user/.rvm/bin/rvm use ruby-1.9.2-p136 rake custom_task >> /home/user/crontab_errors.txt

For daily

0 0 * * * cd /home/user/application_path && /home/user/.rvm/bin/rvm use ruby-1.9.2-p136 rake reminder_email >> /home/user/crontab_errors.txt

Friday, June 8, 2012

rake jobs:work fails - delayed_job

 Hello Guys,
       Do you stuck with the problem to execute rake jobs:work during delayed_job implementation? than follow the below steps.
 Rake.rb
In your rails application's Rakefile add few lines.

begin
  gem 'delayed_job', '~>2.0.5'
  require 'delayed/tasks'
rescue LoadError
  STDERR.puts "rake gems:install` to install delayed_job"
end

Also if you want to use the script/delayed_job start command than add delayed_job under lib folder of rails application.

lib/delayed_job

#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), '.', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize


Now, you do the rake -T to see that delayed_job task are also embed. Hope you will find useful support via this post.