Aug 31
We can include another html page using jquery load method
example is as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Loading an Html page</title>
<script src="jquery.js" type="text/javascript"></script>
$(document).ready(function() {
$('#loadpage').load('load.html or any server side page');
});
</head>
<body>
<div id="loadpage" ></div>
</body>
</html>
Tagged with: css • html • javascript • Jquery
Aug 19
In normal rails application contain one database,but if we want rails application having more than one database that is multiple data base. we can achieve this using multiple way.one of the way is i am showing here.it’s just 3 steps.
Lets take an e.g Project has many milestone and milestone has many task
In normal scenario model looks like following way
class Project < ActiveRecord::Base
has_many :milestones
end
class Milestone < ActiveRecord::Base
has_many :tasks
belongs_to :project
end
class Task < ActiveRecord::Base
belongs_to :milestone
end
Now we want that milestone is stored on milestone_db database and task on task_db database

Now to achieve this we have to do the following steps
1) Edit Database.yml
milestone_dev:
reconnect: false
encoding: utf8
username: <user_name>
adapter: mysql
database: milestone_db
pool: 5
password: <password>
task_dev:
reconnect: false
encoding: utf8
username: <user_name>
adapter: mysql
database: task_db
pool: 5
password: <password>
Now create milestone_db and task_db database.
2) Edit milestone.rb and task.rb
class Milestone < ActiveRecord::Base
#add this line to use milestone_db
self.establish_connection :milestone_dev
has_many :tasks
belongs_to :project
end
class Task < ActiveRecord::Base
#add this line to use task_db
set_table_name "tasks"
belongs_to :milestone
end
3) After editing model edit migration file
class CreateMilestones < ActiveRecord::Migration
def self.connection
Milestone.connection
end
.....
end
Now rails application is ready with multiple database.
Tagged with: multiple database • mysql • rails • ruby on rails
Aug 10
Here it is how we can do that magic,
if( isset($_GET['function']) ) {
switch( $_GET['function'] ) {
case ‘dosomething’:
dosomething();
break;
case ‘dosomethingelse’:
dosomethingelse();
break;
}
}
And then link to script.php?function=dosomething
url rewriting
Benifit :
When a search engine visits the dynamic url like product.php?id=test it does not give much importance to that URL as search engine sees “?” sign treat it as a url which keeps on changing. so we’re converting the dynamic URL like the product.php?id=test to static url format like product-test.html. We’ll rewrite the url in such a way that in browser’s address bar it will display as a product-test.html but it actually calls the file product.php?id=test. So that why these kind of URL also named as SEO friendly URL.
How to do using Apache ?
To rewrite the URL you must have the mod_rewrite module must be loaded in apache server. And furthermore, FollowSymLinks options also need to be enabled otherwise you may encounter 500 Internal Sever Error.
The Procedure
For rewriting the URL, you should create a .htaccess file in the root folder of your web directory. And have to put the following codes as your requirement.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [nc]
The following example will rewrite the test.php to test.html i.e when a URL like http://railstech.com/test.htm is called in address bar it calls the file test.php. As you can see the regular expression in first part of the RewriteRule command and $1 represents the first regular expression of the part of the RewriteRule and [nc] means not case sensitive.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ products.php?id=$1
The following example will rewrite the product.php?id=test to porduct-test.html i.e when a URL like http://railstech/product-test.html calls product.php?id=test automatically.
Tagged with: PHP