Monday, February 1, 2010

Awesome rounded cornered blocks using CSS only - nifty corners

Hi Friends,
To display rounded cornered block in your webpage, most probably we are designing rounded cornered blocks in photoshop then converted the image using css by taking small corner images as source for displaying rounded corner effect, But we can do this by using only css not any images or javascript support needed. The concept is called nifty corners see the demo http://acko.net/files/nifty-aa.html

You can earn money while visitors leaving your website

Hi, you can earn money while visitors leaving your website, the exitjunction will suggest visitors with some ads before leaving your website, So if users clicked on any ad, then your will get income. Why don't you look once, just click on below banner to see more details...

ExitJunction.com  - Make Money From Your Exit Traffic!

Hide default navbar menu and search from your blog

Hi, if you want to hide the default navbar, search and other menus displayed at top, do follow below three stes.

1. Login to Blogger then klick "Layout --> Edit HTML".
2. Copy the code below and insert into your tag styles section.

#navbar-iframe {
display: none !important;
}

Good Luck., happy bloging

Friday, January 29, 2010

Awesome Taxonomy module for categorise content in drupal

Taxonomy is pretty cool for creating categories in drupal. You can create multiple categories and sub categories for each node type. These categories are applied to the partucalar nodes as you mention. So the same category set can be set to multiple content types and also each content type have multiple categories lists. See all about taxonomy at http://groups.drupal.org/taxonomy

A small Tip

A small tip to call methods dynamically using Ruby's send method.

["foo", "bar"].each do |method|
MyClass.send(method)
end

The above code is same as calling MyClass.foo and MyClass.bar.

Make your rails application DRY with constants

Constants help with consistency, they easily allow you to keep your code DRY.
One of the ways I utitilise constants is to standardise the date formatting I use across an app.
For example, in environment.rb I will create a module to contain my date format constants:

module Dates
DATE_FORMAT = "%d% %b %Y"
DATE_TIME_FORMAT = "#{DATE_FORMAT} %H:%M"
end

The module just groups them nicely together. To use the constants I will write the following:

@object.created_at.strftime(Dates::DATE_FORMAT)
@object.created_at.strftime(Dates::DATE_TIME_FORMAT)

Remember you will need to restart your server after making any changes to environment.rb

Helpers usage in ROR

Helpers are basically small snippets of code that can be called in your views to help keep your code DRY - i.e. Any code that you are repeating regularly can most likely be moved into a helper.

Using helpers is simple, each controller has it's own helper file or you can write helpers in the application helper file if it will be used across the entire application. For example a pagination helper might go in there.


def my_helper(opts={}) #args defined as hash
"output something" if opts[:method_passed_in] == "foo"
end

You can then use it in your view with:


<%= my_helper('foo') %>

Ruby on Rails User multiple layouts in single controller

Use multiple layouts in single controller using helpers, one layout per some actions and other for some actions etc..

layout :choose_layout

private
def choose_layout
if [ 'signup', 'login' ].include? action_name
'login'
else
'admin'
end
end

Alternate row colors for table rows in Ruby on Rails

Use the rails builtin helper "cycle" to add alternate row colors to the table rows in a loop.

<%- for item in @items do -%>

tr class="<%= cycle("even", "odd") %>"
... use item ...
/tr

<%- end -%>


Then in your stylesheet add below

tr.even td{
background-color:#CCC;
}

tr.odd td{
background-color:#EEE;
}

Thursday, January 28, 2010

Solution to Undefined method `cache_template_extensions=' in Ruby on Rails

When you upgrade to rails version 2.2.x or later then some times you might get
the below error
Undefined method 'cache_template_extensions='

To fix this problem check your environment.rb and environemts/development.rb, production.rb, test.rb files and comment/remove the below line of co
de.

config.action_view.cache_template_extensions = false

Restart the server and see output.

Solution to uninitialized constant FileColumn::ClassMethods::Inflector in Ruby on Rails

When you install file column plugin in latest version of rails, you might got this noname or uninitialized error. To fix this error open the plugin/lib/file_colum.rb file goto line number 619 and add ActiveSupport:: before the Inflector. See the final code should be like below at line number 619.

my_options = FileColumn::init_options(options,
ActiveSupport::Inflector.underscore(self.name).to_s,
attr.to_s)

Also at line number 79 find and change as below

url << size="4">Restart the server and see the output.

Wednesday, January 20, 2010

Solution to Google checkout payment gateway oops error

When google checkout responds with oops error, you can see the actual problem
by login with your merchant details then Goto

Tools -> Integrated console
There you can see the log of what problems occured while users try to pay you.

Linux chage folder permision to a group

Hi, In linux root have the full permission over entire os and other users will have some previliages only. So when you loggin to the system and want to have write permission to one folder all you have to do, first see the permission of that folder, it contains three blocks,

OWNER - root

GROUP - root

OTHERS --

Here this means all all writes are permitted to root only. If you want to have write permission to this folder, First change the group permission to your group, then provide the write permission to the group. For this follow the below commands

First login as superuser that i.e root for this run command 'su' in the terminal

sudo su

enter root password:

chgrp -R venkat /var/www

#the above command will change the group

chmod -R g+w /var/www

#the above command will provide the write permission to the group

Now the user who logged in as venkat can have the read write permission to the folder var/www





r = read permission
w = write permission
x = execute permission
- = no permission

Ref: http://www.tuxfiles.org/linuxhelp/filepermissions.html

http://www.comptechdoc.org/os/linux/usersguide/linux_ugfilesp.html

Tuesday, January 19, 2010

Remove N/A option for radio buttons and select boxes in Drupal using CCK

Whenever you create a custom form fields with CCK In drupal, it is irritating us by displaying N/A for radio buttons and Selectboxes. You can remove this only through a code. goto modules/cck/modules/optionwidgets.module and find the function named optionwidgets_options() and comment the below code

if (!$field['required']) {
if ((in_array($field['widget']['type'], array('optionwidgets_buttons', 'nodereference_buttons', 'userreference_buttons')) && !$field['multiple'])
|| (in_array($field['widget']['type'], array('optionwidgets_select', 'nodereference_select', 'userreference_select')))) {
$options = array('' => theme('optionwidgets_none', $field)) + $options;
}
}

Now the N/A option is not displayed for radio buttons and select boxes.

Allow users to select Roles while Registration in Drupal

If you want to provide an option for the user to select roles in the registration form, use the module called user selectable roles. The module source url is
http://drupal.org/project/user_selectable_roles
After install it in your application, you should goto administer->user mangement-> user_select_roles
There you can set which roles are displayed in the registration form and other options to select multiple roles selection or single etc.

Restrict accessing your site for some users based on their IP Address

In .htaccess add below lines

Order allow, deny
Deny from 192.168.0.10
Deny from 1.2.3.4 5.6.7.8 127.0.0.1
Allow from all


It is allowed accessing for all except fom IPs 92.168.0.10,
127.0.0.1,127.0.0.2,127.0.0.3


--------------------------------------------------------------
OR if you want to access your site from your IP only add below lines in .htaccess file

Order deny, allow
Deny from all
Allow from 192.178.0.10


This will be usefull for your site administrators.
If you set this for site admin, then the administrator can access admin area from the mentioned IP only.


Run PHP Code in HTML files

If you want to run PHP Code in your static HTML pages, you need to create .htaccess file (if it is not already exists) in the directory of where all your html files exists and add the below lines of code

For web servers using PHP as apache module:

AddType application/x-httpd-php .html .htm

For web servers running PHP as CGI:


AddHandler application/x-httpd-php .html .htm

If your requirement is only for one page then use below code

AddType application/x-httpd-php .html

Thursday, January 7, 2010

Ruby on Rails Fat model and skinny controller

Ruby on Rails controller actions should be very clear and should not contain more than two instance variables in an action. So almost write everything in model as the methods and call them in controller actions. I write a code below for how to done it to get related galleris.
#app/model/gallery.rb
class Gallery < ActiveRecord::Base

def self.get_related(galname)
related = find(:all, :conditions => ['name like ?', '%'+galname+'%'])
end
end

#app/controllers/galleries_controller.rb
class GalleriesController < ApplicationController
def show
@gallery = Gallery.find(params[:id])
@related = Gallery.get_related(@gallery.name)
end
end

#app/views/galleris/show.rhtml

Related Galleries


<% @related.each do |relate|%>
<% if (relate.id!=@gallery.id)%>


<%= link_to( relate.name , { :action=>'show', :id=>relate.id}) %>


<% end %>
<% end %>

Ruby on Rails shareble content or menus processing

Store the common menus or links in some where in app/views folder with filename prefixing with _. Ex store the links in app/views/shared/_global_links.rhtml file and call it in app/views/layouts/application.rhtml file.

Ex: app/views/shared/_global_links.rhtml
<% if logged_in? %>
<%= current_user.login %> |
<%= link_to "Dashboard", root_url %> |
<%= link_to "My Account", profile_url(current_user) %> |
<% if admin? -%><%= link_to "Administration", admin_root_url %> | <% end -%>
<%= link_to "Log out", logout_url, :method => :delete %>
<% else %>
<%= link_to "Sign up", signup_url %> |
<%= link_to "Log in", login_url %>
<% end %>

#app/views/layouts/application.rhtml
-------------------------------------------------------
-------------------------------------------------------

<%= render :partial => 'shared/global_links' %>

-------------------------------------------------------
-------------------------------------------------------

Ruby on Rails Dynamic content blocks using contentfor and yield helpers

In app/views/layouts/application.rhtml design application layout and set some right block. The content in that rightcolumn is dynamically filled by the view
----------------------------------------------------------

<%= yield_or_default(yield(:sidebar)) %>

-----------------------------------------------------------

In app/views/users/index.rhtml you should set the content for rightcolumn for the users page like below
-----------------------------------------------------------
<% content_for :sidebar do -%>

Sidebar



<% end -%>
-----------------------------------------------------------

In In app/views/movies/index.rhtml you should set the content for rightcolumn for this movies page like below
-----------------------------------------------------------
<% content_for :sidebar do -%>
some movies related information you can place here
<% end -%>
-----------------------------------------------------------