Friday, August 30, 2013

Tagging in Rails

A very simple plugin to implement tagging feature in rails application is acts-as-taggable-on. Install the gem, specify the field in the model on which you want to put tags, add a tag field in the form, and you are ready to tag your model object. Implementation details can be found in following links.

https://github.com/mbleigh/acts-as-taggable-on

http://railscasts.com/episodes/382-tagging
http://alexmuraro.me/posts/acts-as-taggable-on-a-short-tutorial/

Popularity of this plugin can be found in The Ruby Toolbox -
https://www.ruby-toolbox.com/categories/rails_tagging

Limiting loop for array of objects in Rails


While fetching records from DB, we can definitely limit the number of records to fetch as following.
@post.comments.limit(10).each do |comment|
   comment.description
end
But in practical, sometimes we face that we have an array of objects fetched from DB and we want to access first or last few objects. Using following code we can easily solve it. 

Reading first 10 records -
@posts.first(10).each do |post|
   post.title
end
Reading last 10 records -
@posts.last(10).each do |post|
   post.title
end

Wednesday, August 7, 2013

Creating Page and Subpage in Wordpress

Creating Page

Step 1: Login as admin. It will show you admin dashboard (admin panel).


Step 2: Go to Pages link and press Add New link.


Step 3: Enter page Title that will be shown in your page as page title. For this example, you can give hello world. In the description box, write some text that you want to show in your page, for now you can write “hello world page crated successfully”.

Step 3: Click on the Publish button on right sidebar and your page is ready to view. If you do not want to show this page in your website then do not publish it, just save it as draft using Save Draft button on left top corner.


Step 4: Go to wordpress site from your browser and you will see hello world link in the manu bar. Click that link and it will show you the page that you have just created.


Creating Subpage

We want to create a page which will be a subpage of our previous hello world page. Follow the steps of creating page, go to the page creation form. On the right side, Parent option of Page Attributes is used to create subpages. Parent option shows all created pages. While creating page, you have to select a page here to make it parent of the creating page. In our case, we choose “Hello World” page so that it would be a subpage of our hello world page.


Give the page title and its content in the appropriate places and publish the page. If we visit the site, this subpage link will appear under hello world link and using that link we can browse that page.



Sunday, August 4, 2013

Installing and Running Wordpress using XAMPP

Few steps to install wordpress using XAMPP are as following:

Step 1: Create a database for wordpress without table. You will need database name, username, password, etc. later to setup and use wordpress.

Step 2: Download wordpress zip from its website - http://wordpress.org/download/.

Step 3: Extract zip and copy wordpress folder in your /xampp/htdocs folder.

Step 4: Rename file  wp-config-sample.php to wp-config.php under wordpress folder.

Step 5: Edit this config file to enter database information. Following information will be needed to modify in config file –
  • DB_NAME - your wordpress database name.
  • DB_USER – database username.
  • DB_PASSWORD – password for given database username.
  • DB_HOST – address of the database, for local pc it will be localhost or 127.0.0.1 .
Step 6: From your browser go to wordpress (http://localhost/wordpress). It will ask you to give some information to setup wordpress. Give necessary information and submit. After configuring wordpress it will redirect you to a page showing success message and you are ready to use wordpress.

For installation details, you may visit wordpress official installation guide here - http://codex.wordpress.org/Installing_WordPress