Wednesday, September 24, 2008

observe_field Example - Ruby on Rails

<td><label for="searchtext"><font size="1"><b>Live Book Search:</b></font></label></td>
<td><%= text_field_tag :searchtext %></td>
<td><img alt="spinner" id="spinner" src="/images/spinner.gif" style="display:none;" /></td>

<%= observe_field 'searchtext', :frequency => 0.5,
:update => 'search_hits',
:loading => "'spinner')",
:complete => "Element.hide('spinner')",
:url => { :controller => 'books', :action=> 'live_search' },
:with => "'search=' + escape(value)" %>

<div id="search_hits">

<% for book in @books %>
<td><%=h %></td>
<td><%=h %></td>
<td><%=h book.price %></td>
<td><%=h book.desc %></td>
<td><%= link_to 'Show', book %></td>
<td><%= link_to 'Edit', edit_book_path(book) %></td>
<td><%= link_to 'Destroy', book, :confirm => 'Are you sure?', :method => :delete %></td>
<% end %>

For more detail go to

Variables In Request Env - Ruby on Rails

request.env is a Ruby Array that contains information about a visiting user’s and server environments.
request.env is accessible on all pages hosted in a ruby on rails site. The Array contains the following key/value pairs:

For testing purposes it might be useful to print out a table with the request.env information in it.

<% for item in request.env %>
<td><%= item[0] %></td>
<td><%= item[1] %></td>
<% end %>

Installing Rmagick on Windows Using Ruby 1.8.6

Rmagick tends to be tricky to install, but on windows its relatively simple, except for the fact that if you freshly installed ruby 1.8.6, ruby gems needs to be updated. If you install ruby 1.8.6 and then go to ruby.forge and download rmagick for windows. Extract the zip folder, run the .exe, then open a command line, cd (change directory) to the install folder and do “gem install rmagick —local”. The first time you do this, you might run into the “Error installing gem RMagick (version) .gem[.gem]: buffer error”. To fix that run “gem update —system” with double hyphens and then run “gem install rmagick —local” and everything should now install fine.

Dynamically add and remove html elements using javascript

<input type="hidden" value="0" id="theValue" />
<p><a href="javascript:;" onclick="addElement();">Add Some Elements</a></p>
<div id="myDiv"> </div>

function addElement() {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1)+ 2;
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = 'my'+num+'Div';
newdiv.innerHTML = 'Element Number '+num+' has been added! <a href=\'#\' onclick=\'removeElement('+divIdName+')\'>Remove the div "'+divIdName+'"</a>';

function removeElement(divNum) {
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);

Monday, August 25, 2008

NAMED_SCOPE in Ruby on Rails

The has_finder gem has been added to Rails with a different name: named_scope

For better understand let go through the following example:

class Article < ActiveRecord :: Base
named_scope :published, :conditions => {:published => true}

named_scope :containing_the_letter_c, :conditions => "author LIKE '%c%’"

Article.published.paginate(:page => 1)

Instead of creating a new method named published to return all published posts, I'm using a named_scope to do it for me.
But it can go even further than this. Let's look at another example of how it can be used:

named_scope :written_before, lambda { |time|
{ :conditions => ['written_on < ?', time] }

Search from multiple tables in mysql

CREATE TABLE `tagsearch`.`books` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(200) NOT NULL,
`author` varchar(100) NOT NULL,
`price` float(10,2) NOT NULL,
`comment` text,
`created_on` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',

CREATE TABLE `tagsearch`.`tags` (
`id` int(11) NOT NULL auto_increment,
`tagname` varchar(200) NOT NULL,
`counter` int(10) NOT NULL default '0',
`created_on` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`updated_on` timestamp NOT NULL default '0000-00-00 00:00:00',

Suppose we have in database these two tables.... and search query is as below.....

select * from books,tags WHERE MATCH(author,comment,tagname) AGAINST ('rails' in boolean mode);

Here, keyword is search from two tables and Match includes the field name of different table and against have search keyword

Friday, July 18, 2008

validate positive integer value in model - Ruby on Rails

validates_inclusion_of :some_attribute,

:within => 1..1.0/0,

:message => 'should be positive'

here 1.0/0 it means infinity...

So the attribute is validate within positive. It is done in rails with validates_inclusion_of for numeric data.

Create Application in RoR in specific Rails Version if we have multiple rails installed

cd ..
rails _1.2.6_ test
cd test

here test is the application name... like wise we can cerate any other application in any specific rails version
It happen while we have multiple rails versions in our system...

Wednesday, July 16, 2008

Excel Your Job Interview !!! (Takes 2 mins) !!

Interviews are often the most dreaded part of the job search process, but they need not be. With a little preparation, interviews become effortless and you can secure the job you want. When you sit to write an exam, you studied in advance. Its the same with interviews, but fortunately, not nearly as taxing as preparing for an exam. The steps themselves are simple, and dont require much in terms of preparation.

First, anticipate the likely questions. Sit and think about what sort of questions you would ask, if you were conducting the interview. Its impossible to anticipate every question, but think of some big ones, and even if they don`t get asked, they will be good preparation for other questions and provide you a base to answer from.

First impressions last. Sad but true. When it comes to an interview, you must take care to put forward the right image. This extends to personal hygeine, being clean shaven, having clean nails and so on. You want to convey an image of professionalism.

Our bodies communicate volumes of information. Trained interviewers can read your body language like a poker pro. While we cant hide the messages our body sends, we can control and shape those messages to improve the impression we give to the interviewer.

21 Ways to increase Self Motivation!!!

21 Ways to increase Self Motivation!!!

1. Consequences - Never use threats. They’ll turn people against you. But making people aware of the negative consequences of not getting results (for everyone involved) can have a big impact. This one is also big for self motivation. If you don’t get your act together, will you ever get what you want?

2. Pleasure - This is the old carrot on a stick technique. Providing pleasurable rewards creates eager and productive people.

3. Performance incentives - Appeal to people’s selfish nature. Give them the opportunity to earn more for themselves by earning more for you.

4. Detailed instructions - If you want a specific result, give specific instructions. People work better when they know exactly what’s expected.

5. Short and long term goals - Use both short and long term goals to guide the action process and create an overall philosophy.

6. Kindness - Get people on your side and they’ll want to help you. Piss them off and they’ll do everything they can to screw you over.

7. Deadlines - Many people are most productive right before a big deadline. They also have a hard time focusing until that deadline is looming overhead. Use this to your advantage by setting up a series of mini-deadlines building up to an end result.

8. Team Spirit - Create an environment of camaraderie. People work more effectively when they feel like part of team — they don’t want to let others down.

10. Recognize achievement - Make a point to recognize achievements one-on-one and also in group settings. People like to see that their work isn’t being ignored.

11. Personal stake - Think about the personal stake of others. What do they need? By understanding this you’ll be able to keep people happy and productive.

12. Concentrate on outcomes - No one likes to work with someone standing over their shoulder. Focus on outcomes — make it clear what you want and cut people loose to get it done on their own.

13. Trust and Respect - Give people the trust and respect they deserve and they’ll respond to requests much more favorably.

14. Create challenges - People are happy when they’re progressing towards a goal. Give them the opportunity to face new and difficult problems and they’ll be more enthusiastic.

15. Let people be creative - Don’t expect everyone to do things your way. Allowing people to be creative creates a more optimistic environment and can lead to awesome new ideas.

16. Constructive criticism - Often people don’t realize what they’re doing wrong. Let them know. Most people want to improve and will make an effort once they know how to do it.

17. Demand improvement - Don’t let people stagnate. Each time someone advances raise the bar a little higher (especially for yourself).

18. Make it fun - Work is most enjoyable when it doesn’t feel like work at all. Let people have fun and the positive environment will lead to better results.

19. Create opportunities - Give people the opportunity to advance. Let them know that hard work will pay off.

20. Communication - Keep the communication channels open. By being aware of potential problems you can fix them before a serious dispute arises.

21. Make it stimulating - Mix it up. Don’t ask people to do the same boring tasks all the time. A stimulating environment creates enthusiasm and the opportunity for “big picture” thinking.

Wednesday, June 11, 2008

I am working with Ruby on Rails since july 2007. I have finished my MCA with 67%.

I do RoR web application development along with other technologies like LAMP.I havealready finished and worked in some sites like event management system ,,talentlaunchpad,,gujaratcricket, etc., So these all are with different functionalities.

The reason to love programming with RoR is, it helps keep code simple, clean and nice…

I have also work with PHP (LAMP Technology). for 7-8 months.
In php i have also developed some web aplications like unitedway,B2C web,and aprisal web portal etc.

Contact Me for any help regarding rails/nodejs/php/mysql


Email *

Message *