Sunday, November 30, 2008

undefined method 'scaffold' - Ruby on Rails error

When I first got the error undefined method 'scaffold' I was so frustrated because I was new to Ruby on Rails and was following a tutorial. After some search on the net I found out that method scaffold is no longer supported in Rails 2.0 and above.
Tutorials out there in the net really need to be updated because newcomers are stuck when they get errors in the tutorial it self.

Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Saturday, November 29, 2008

InstantRails 2.0 - Default Database is SQLite3, How to change into mysql

InstantRails 2.0 or higher versions comes with the SQLite3 as the default database,
So a command like this rails my_app will take SQLite3 as the default database for the Rails application.

To use mysql try the following command:
rails -d mysql my_app

extra parameter -d will define database

Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Friday, November 28, 2008

Ruby on Rails quick guide with InstantRails

Lets get started quickly on Ruby on Rails basics with InstantRails, First we'll see how to add a new Rails application using InstantRails ruby console.

1) Start up your InstantRails.

2) Right Click the InstantRails system tray icon and goto Rails Applications -> Open Ruby Console Window

3)you will be in rails_apps folder(default) in the command line.

4)type rails my_new_site on the command line

This will create a new my_new_site rails application inside the rails_apps folder, all the files needed will be created for you as well, just navigate to your rails_apps folder and view newly created my_new_site folder.



5) now lets start our web server to run our newly created RoR application using the command line

6) type cd my_new_site (change directory to my_new_site)

7) type ruby script\server
Now your web server is started and you can run your new application.




8) open a browser and type http://localhost:3000/ in the navigation bar.



To learn how to install InstantRails click here

Get custom programming done at GetAFreelancer.com!

Thursday, November 27, 2008

How to install Ruby on Rails - Instant Rails - All in one Package

If you are going to learn Ruby on Rails (RoR), Instant rails will make your RoR installation much more easier, like WAMP Server for php, Instant Rails is all in one package containing Ruby, Rails, Apache, and MySQL. All the things have been configured for you that you only need download and unzip the Instant Rail folder to your C: drive.

1) Download Instant Rails from here Download the latest zip file (InstantRails-2.0-win.zip when I write this)

2)Unzip the Instant Rail into C:\InstantRails

3)Double click the InstantRails.exe (Icon with big red I)

4)Now InstantRails system tray icon will run on you Taskbar

5)To see if all went well, Right Click the InstantRails system tray icon and goto Rails Applications -> Open Ruby Console Window



6)Type ruby --version in the opened command line window, then you will get the installed ruby version.

OK that's it. In my next blog post I will cover some basics when working with InstantRails for your RoR development.

Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Wednesday, November 26, 2008

How to get the Square root of a numeric value using php - sqrt()

Following code will show you how to get the Square root of a given numeric value.


<?php

echo sqrt(4); // 2

echo sqrt(12); // 3.4641016151378

echo sqrt(16); // 4

echo sqrt(17); // 4.1231056256177

?>


Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Tuesday, November 25, 2008

How to round a floating point number in php - round()

Following code will show you several examples on how to round a floating numeric value as you like.


<?php

echo round(10.8); // 11
echo '<br />';
echo round(10.4); // 10
echo '<br />';

/*you can also set the number of precision,
or in other words number of decimal digits
you like to round the floating number
*/

echo round(10.837, 2); // 10.84
echo '<br />';
echo round(10.435767, 4); // 10.4358
echo '<br />';

?>


Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Monday, November 24, 2008

How to create a dynamic pdf file using php - FPDF fpdf.org

If you need to create dynamic or on the fly pdf files using php, usually we use PDFlib library. but PDFlib library sometimes not available in all hosting packages.
FPDF is a good alternative for PDFlib library, FPDF is a Free php class that you can easily include in you php code, really easy and simple to use FPDF is my choice when creating pdf files on the fly.

www.fpdf.org

Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Thursday, November 20, 2008

How to split a string using javascript - split() method

Following code will show you how to split a string using a given separator.



<head>

<script type="text/javascript">

var my_string = "Hello My Name Is Kusal";
var split_var = my_string.split(" "); //separate by space

alert(split_var[0]); //Hello
alert(split_var[1]); //My
alert(split_var[4]); //Kusal

</script>

</head>



Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Friday, November 14, 2008

How to add RGB color values for select box or a DIV tag

Following code will show you two exapmles on how to add RGB color values to a Select DropDown Box and a DIV tag.


<body>

<select name="colors">
<option>Select</option>
<option style="background-color:rgb(200,250,300);">Color 1</option>
<option style="background-color:rgb(100,89,200);">Color 2</option>
<option style="background-color:rgb(65,89,50);">Color 2</option>

</select>

<br /><br />

<div style="background-color:rgb(200,100,100);">Hello</div>

</body>


Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Monday, November 10, 2008

How to search/scan files inside a directory using php - scandir()

Lets see how we can scan or search files inside a directory using php. You can use scandir() for this matter. scandir() will go through the given directory and return all the files in an array.


<?php

$dir_path = 'kusal/test'; //directory path
$list_files = scandir($dir_path);

//dumping the array
//hope you know how to access an array
echo '<pre>'; //html <pre> tags will format the output
print_r($list_files);
echo '</pre>';

/*
Output look like this

Array
(
[0] => .
[1] => ..
[2] => TextDocument.txt
[3] => kuppiya.doc
[4] => lion.ppt
[5] => test.as
)

*/

?>



Get Free Sinhala IT Learning Videos Kuppiya.com


Get custom programming done at GetAFreelancer.com!

Friday, November 7, 2008

How to delete a directory using php - rmdir()

Lets see how can we delete a folder using php.
You can use rmdir() function to do this task, before using this function you should remember that you can only delete empty folders


<?php

$path = 'path to directory'

//First Check if deleting a directory
if(is_dir($path))
{
//remove directory
if(rmdir($path))
{
echo 'Deleted';
}
else
{
echo 'error';
}
}
else
{
echo 'Not a directory';
}
?>


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

Sunday, November 2, 2008

How to use getElementById in JavaScript

Following codes will show you how easy it is to use JavaScript getElementById to manipulate HTML elements.

Example 1 - On mouse over the text will be red, on mouse out it will be black again.


<html>
<head>

<script type="text/javascript">

function chng_color()
{
document.getElementById('my_div').style.color = 'red';
}

function normal_color()
{
document.getElementById('my_div').style.color = 'black';
}

</script>

</head>

<body>

<div id="my_div" onmouseover="chng_color()" onMouseOut="normal_color()">

This is the first example!!!

</div>

</body>
</html>


Example 2 - Get entered text of a text box and display it on a JavaScript alert box.


<html>
<head>

<script type="text/javascript">

function alrt_text()
{
var entered_text = document.getElementById('my_text_box').value;
alert(entered_text);
}

</script>

</head>

<body>

Your Text:
<input type="text" name="my_text_box" id="my_text_box" onBlur="alrt_text()" />

</body>
</html>


*Always remeber to give a id name for your HTML elements before using getElementById()

Get Free Sinhala IT Learning Videos Kuppiya.com

Subscribe To My Blog