Monday, February 1, 2010
Awesome rounded cornered blocks using CSS only - nifty corners
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
Hide default navbar menu and search from your blog
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
A small Tip
["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
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
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
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
<%- 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
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 code.
config.action_view.cache_template_extensions = false
Restart the server and see output.
Solution to uninitialized constant FileColumn::ClassMethods::Inflector in Ruby on Rails
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
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
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
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
For web servers using PHP as apache module:
AddType application/x-httpd-php .html .htm
For web servers running PHP as CGI:
If your requirement is only for one page then use below code
AddHandler application/x-httpd-php .html .htm
AddType application/x-httpd-php .html
Thursday, January 7, 2010
Ruby on Rails Fat model and skinny controller
#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
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
----------------------------------------------------------
<%= 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
- Add your photos
- View your galleries
- <%= link_to "Log in", login_url %> Login
<% if logged_in? %>
<% else %>
<% end %>
<% 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 -%>
-----------------------------------------------------------