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