Monday, December 28, 2009

74 Quality Ruby on Rails Resources and Tutorials

There are so many resources and tutorials available on net for a very popular programming language ruby on rails as its open source, but many people don't know which are the best sites to follow.

Softwaredeveloper.com is providing list or we can say guide of 74 Quality Ruby on Rails Resources and Tutorials in one place.
Cool.

Installing gem ferret without nmake error

Gem's like ferret, ruby-debug throws nmake errors while installing those. Like I got when I was installing ferret
$ gem install ferret
Building native extensions. This could take a while...
ERROR: Error installing ferret:
ERROR: Failed to build gem native extension.

c:/ruby/bin/ruby.exe extconf.rb
creating Makefile

nmake
'nmake' is not recognized as an internal or external command,
operable program or batch file.


Gem files will remain installed in c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.11.6
for inspection.
Results logged to c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.11.6/ext/gem_make.out


To avoid this go to rubyforge.com and then just download gem file which name holds "mswin32", the gem will be installed with no nmake errors.

Friday, November 27, 2009

Regular Expressions Editor

Understanding regular expressions is difficult and coding that is more.
But what if we have plenty of resources available, like regexlib.com where we can find many libraries for regular expressions at one place.

There are also other testing tools like regtest AND
Rubular, which is a Ruby-based regular expression editor, a very handy tool and can be found at rubular

http://www.javascriptkit.com/javatutors/redev.shtml

Thursday, November 19, 2009

Rails Best Practices

Rails best practices is really a good gem to understand and modify your rails project according to the rails real environment, where your project's performance increases.
Just run
gem install rails_best_practices
Then go in to the project and just run this command
rails_best_practices .
This will take some very small time and let you know what are the best practices you should take and move your code to other place to make your project run at faster speed. And once you get the list just check out this SlideShare Presentation:

Wednesday, August 19, 2009

Using marquee

Code of marquee to scroll images

<ul>
<marquee behavior="alternate" direction="left" scrollamount="1" align="center" >
<li> <img src="/images/image1.png" alt="image1" /> </li>
<li> <img src="/images/image2.png" alt="image2" /> </li>
<li> <img src="/images/image3.png" alt="image3" /> </li>
<li> <img src="/images/image4.png" alt="image4" /> </li>
<li> <img src="/images/image5.png" alt="image5" /> </li>
</marquee>
</ul>

In CSS
ul li{margin:0; padding:0; display:inline; float:left;}

If we start increasing the scrollamout of the marquee the speed of the content in the marquee will rise.

Other marquee attributes can be found at blooberry.com

Wednesday, August 12, 2009

undefined method 'collect' after installing one click installer

After Installing ruby with one click installer never forget to update the gems:
gem install rubygems-update
gem update --system

If you don't do so you will get bunch of errors at gitbash/ command prompt what ever you use
the error will be for sh.exe

rake aborted!
undefined method `collect' for #. . . . . . . .

You can see full trace by running task with --trace

After getting these message if you update the gems and the projects will start running properly and you will get something like this
Deprecation Notices:

* Bulk index update is no longer supported (the code currently remains, but not the tests)
* Gem::manage_gems was removed in 1.3.3.
* Time::today was removed in 1.3.3.

</gem::version::requirement:0x493a43c>


http://www.getontracks.org/forums/viewthread/402/

Friday, July 17, 2009

onchange and IE

onChange event handler, not supported by Internet Explorer, which is really bad.
As I was using checkbox, which has to hide or show other div on true/ false when checkbox changes its behaviour.

After a study I found that IE waits to loose the focus from the checkbox. As soon as I click on other object or on the page to make it work.

You can see working example at krijnhoetmer.nl
In MSDN Forum they have used setTimeout Window Function. But this didn't work for me.

The only solution worked for me was replacing onChange with onClick event handler.

Thursday, July 16, 2009

PNG in IE6

PNG image format is so useful while making images transparent, but the question arrives that whether it supports all the browsers or not. Well latest browsers do support this format but the problem occurs when we deal with IE6.
Even though we now have IE8, still usage of IE6 is 14.9%.

You can find the latest Browser Statistics Month by Month at w3schools

For that we always use the following available IE6 Hack
In CSS
#trans-content{
background:url(section.png) repeat;
width:100%;
height:260px;
margin:0;
padding:0; }
and
* html #trans-content{background-image:none; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='section.png', sizingMethod='scale');}

Tuesday, June 23, 2009

min-height behaviour in firefox 3.0

Min-height property is very useful for designing a site. Although it was not working in IE6 but hack was available. And even if there was height specified it expands automatically after gettign more than that height.
I have Firefox 3.0.11 installed and when I checked "#wrapper{min-height:100%}" it didn't work at all. That was strange as I used this in my previous designs.
But when I replace the 100% with 400px it started working properly.

Saturday, June 20, 2009

Simple Restriction while deleting a record in rails

Adding validations to rails application is really simple and we also get help from rails api.
We can also delete the dependent with a record.

But what if we don't want to delete a record when we have dependent.
I got this solution from the post of Sachin.
Just took dependent and if there is no dependent only then delete this record.

Simple and quick solution. Thanks Sachin.

Thursday, June 18, 2009

Javascript Page flip effect

Its really cool when we watch the page flip effect in Flash.
Flash and actionscript can just do anything.
For example flashpageflip.com



They are also giving facility to download.

But what if we get not exactly but something similar in javascript.
You can get the demo as well as code at coastworx.com



Or even Javascript Pageflip by Charles Mangin at his site.

Sunday, June 14, 2009

Easy Field Validation with Prototype

Giving validations in rails applications is really simple and nice, but if we can display validations with cool javascript effect, the application really looks effective.

This is possible with using prototype library and adding validations.js by Andrew Tetlaw. You can find documentation and demo.

The code really works fine and with really nice effects. If any one wants to add image, can alter the code little bit and change the validation div to the span in javascript itself and add image_tag. We can also add our own validations.

Only problem occurs when using calendar_date_select plugin and error hits. calendar_date_select link stops working.
If not using calendar_date_select these validations rocks. I will definitely prefer to use these.

Wednesday, June 10, 2009

Setting up flash for local as well as network access

Publishing the flash file gives only 2 option whether we want to access network or local but what if we want access both?



Flash files setting up for local and network access is very simple.
Just go to Flash Player Setting Manager and set the global settings.



Add the location and select the option from given radio buttons and you are done.
Now you can access not only network but also can add local files.
This will help for adding functionality like downloading files or photo gallery.

Monday, June 8, 2009

Using Prototype and jQuery together

I thought that prototype and jQuery using together is like impossible.

As I was using lightbox by prototype but also need the dockmenu by jQuery.
The result: jQuery menu was working well but the prototype lightbox just disabled.

Didn't find much until this one life saving post by Benjamin Smith.

And both the scripts started working well, no errors and headaches.
If want to use jQuery with other library you can read this reference.

Sunday, June 7, 2009

Gruff vertical labels

As I was working on the project which has pdf reporting functionality, which also contains charts and other related data.
So need to convert those charts to printer friendly images, which was possible through gruff graphs for ruby.
But X-axis labels were so long that those can not stay on one line.
So I tried to make it vertical with help of post by mrtibs vertical labels in gruff which really helped.
But problem with that was labels should go at the bottom of the chart and not at the top.
So instead of
y_offset = @graph_bottom + LABEL_MARGIN

we used
y_offset = ((@graph_height / 2) + (@graph_top * 3) - 5 )

which worked for me a bit but not fully functional.

Saturday, June 6, 2009

Simple popup with cool effects

There are many ways of adding popup in the application. But the most simple and beautiful way of adding it will be with the help of prototype, scriptaculous and very little CSS.

Prototype.js is a javascript library written by Sam Stephenson. And adding scriptaculous with that will help to add amazing cool effects for displaying information more effectively.

For example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Simple popup with cool effects </title>
<script src="prototype.js" type="text/javascript"></script>
<script src="scriptaculous.js?load=effects" type="text/javascript"></script>
<style type="text/css">
body{
background:#CFDEE2;
margin:0;
font:11px verdana;}

a {
color:#fff;
font-weight:bold;
text-decoration:none}
a:hover{ text-decoration:underline}

#title{
background:#CB6D23;
margin:0;
padding:0;
height:40px;
line-height:40px;}

#close{
background:#CB6D23;
margin:0;
padding:0;
height:30px;
line-height:30px;}

#close a{ float:right;}

#close a:hover{ text-decoration:none}

#wrapper{
width:600px;
height:100%;
margin:0 auto;
background:#fff}

p{width:80%; margin:20px auto}

#hiddendiv{
position:absolute;
background: #fff;
top:50%;
left:50%;
margin: -100px 0 0 -200px;
width: 400px;
height: 200px;
border: 4px solid #CB6D23}

</style>
</head>
<body>
<div id="wrapper">

<div id="title"> <a href="#" onclick="$('hiddendiv').appear(); return false;">Show me the popup</a></div>
<div id="hiddendiv" style="display:none">
<div id="close"> <a href="#" onclick="$('hiddendiv').fade(); return false;">[X]</a> </div>
<div> You can also give some other cool effects to this popup. </div>
</div> <p>This is the most easy way of adding the popup with cool effects. </p> </div>

</body>
</html>


Other effects can be found at scriptaculous combination of effects.

And can download from here

Thursday, June 4, 2009

Sending mail through ruby on rails

I was working for site and needed something like this for contact form.

http://www.tutorialspoint.com/ruby-on-rails-2.1/rails-send-emails.htm
is really nice tutorial for sending mails , can be used for static sites. This helped me a lot.

But faced some problems,
I didn't get subject and message although the mail was going to the right address.
It was merging with the message and passing through the recipients only .
No other field required for that

so I made some changes in that

in (model) ContactMailer.rd
def contact(recipient, subject, message)
  @subject = "message:: "+subject 
  @message = message
  @recipients = 'your@email.com' 
  @sent_on = Time.now
  @from = recipient
end
and in ContactController.rb
def sendmail
  email = params[:email]
  subject = email[:subject]
  recipient = email[:recipient]
  message = email[:message]
  ContactMailer.deliver_contact(recipient, subject, message)
  return if request.xhr?
  render :text => 'Message sent successfully'
end