Wednesday, August 29, 2012

undefined method

Hello Guys,
            When i was trying to configure browser cms along with ruby 1.8.7 and rails 2.3.11. It raise the error like `==': undefined method `name' for "abstract":String.

Than i have find the related solution. So follow below things.

Replace method ==(other) at gems/rails-2.3.11/lib/rails/gem_dependency.rb:277

def ==(other)
   if self.respond_to?(:name) && other.respond_to?(:name)
       self.name == other.name && self.requirement == other.requirement
    else
      if other.respond_to?(:requirement)
        self.requirement == other.requirement
      else
        false
      end
    end
end

Hope this will save you life :)

Saturday, August 4, 2012

Replace double space with   in javascript

Hello Guys,
        Last time when i was playing with double spaces.. found the interesting thing. When passing the double space string from javascript (view) to controller , it converts the valid space to non-breaking space.

Lets see the eg.

View: index.rhtml

a = "This  is the pen"
a.gsub("  ", " &nsbsp;")

<script language='javascript/text'>
 
  /* Now assign the value to input element by */
  $('txtid').value = <%= a %>;

 // Get value back encodeURIComponent($('txtid'))

</script>
 
at controller

def any_method
   # replace '\xC2\xA0' or '&nbsp;' with ' '
   params[:a].gsub("\xC2\xA0", " ").gsub("&nbsp;", " ")
end

Hope above article is helpful to you guys.

Disable right mouse click script

Hello Guys,
        Wanna to disable the right click? Follow the below JavaScript to achieve that.

eg.
test.html

<html>
  <body>
    <div id='img'>
       <%= image_tag('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH4hixyVqT9hmPJ3J2xBoC7972VOGveRP864H_eGjWZyeIrzxVdHs3GgshxDAS0LdvmtzFBmSxNw8yC3Plz7zUH2fE594sKTp2FTvbaITKcM1ajz8u8GTTMbol3KXUJLs5NPtdfLqc_A/s220-h/cutex.jpeg') %>
    </div>
  </body>
 
  <script language="javascript" type="text/javascript">
 
   // Disable right click 
   var message = "you can't right click on image";

   function clickIE4(){
     if (event.button == 2) {
        return false;
    }
  }

  function clickNS4(e){

    if (document.layers || document.getElementById && !document.all) {
   
      if (e.which == 2 || e.which == 3) {
          return false;
      }
    }
  }

  if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown = clickNS4;
  }
  else
    if (document.all && !document.getElementById) {
      document.onmousedown = clickIE4;       
    }

   document.oncontextmenu = new Function("alert(message); return false")
  </script>
</html>