<table>
<tr>
<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>
</tr>
</table>
<%= observe_field 'searchtext', :frequency => 0.5,
:update => 'search_hits',
:loading => "Element.show('spinner')",
:complete => "Element.hide('spinner')",
:url => { :controller => 'books', :action=> 'live_search' },
:with => "'search=' + escape(value)" %>
<div id="search_hits">
<table>
<tr>
<th>Name</th>
<th>Author</th>
<th>Price</th>
<th>Desc</th>
</tr>
<% for book in @books %>
<tr>
<td><%=h book.name %></td>
<td><%=h book.author %></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>
</tr>
<% end %>
</table>
For more detail go to
Wiki.rubyonrails.org
Working with Ruby on Rails since july 2007. RoR web application development along with other technologies like LAMP.The reason to love programming with RoR is, it helps keep code simple, clean and nice… Also working with php/cakephp etc.
Wednesday, September 24, 2008
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:- SERVER_NAME
- PATH_INFO
- REMOTE_HOST
- HTTP_ACCEPT_ENCODING
- HTTP_USER_AGENT
- SERVER_PROTOCOL
- HTTP_CACHE_CONTROL
- HTTP_ACCEPT_LANGUAGE
- HTTP_HOST
- REMOTE_ADDR
- SERVER_SOFTWARE
- HTTP_KEEP_ALIVE
- HTTP_REFERER
- HTTP_COOKIE
- HTTP_ACCEPT_CHARSET
- REQUEST_URI
- SERVER_PORT
- GATEWAY_INTERFACE
- QUERY_STRING
- REMOTE_USER
- HTTP_ACCEPT
- REQUEST_METHOD
- HTTP_CONNECTION
request.env
information in it.<table>
<th>key</th>
<th>Value</th>
<% for item in request.env %>
<tr>
<td><%= item[0] %></td>
<td><%= item[1] %></td>
</tr>
<% end %>
</table>
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>
<script>
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.setAttribute('id',divIdName);
newdiv.innerHTML = 'Element Number '+num+' has been added! <a href=\'#\' onclick=\'removeElement('+divIdName+')\'>Remove the div "'+divIdName+'"</a>';
ni.appendChild(newdiv);
}
function removeElement(divNum) {
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
</script>
<p><a href="javascript:;" onclick="addElement();">Add Some Elements</a></p>
<div id="myDiv"> </div>
<script>
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.setAttribute('id',divIdName);
newdiv.innerHTML = 'Element Number '+num+' has been added! <a href=\'#\' onclick=\'removeElement('+divIdName+')\'>Remove the div "'+divIdName+'"</a>';
ni.appendChild(newdiv);
}
function removeElement(divNum) {
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}
</script>
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%’"
end
Article.published.paginate(:page => 1)
Article.published.containing_the_letter_c.count
Article.containing_the_letter_c.find(:first)
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] }
}
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%’"
end
Article.published.paginate(:page => 1)
Article.published.containing_the_letter_c.count
Article.containing_the_letter_c.find(:first)
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',
PRIMARY KEY (`id`)
)
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',
PRIMARY KEY (`id`)
)
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
`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',
PRIMARY KEY (`id`)
)
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',
PRIMARY KEY (`id`)
)
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...
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 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.
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 ,citiplots.com,talentlaunchpad,railshouse.com,gujaratcricket,marketdhoom.com 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.
I do RoR web application development along with other technologies like LAMP.I havealready finished and worked in some sites like event management system ,citiplots.com,talentlaunchpad,railshouse.com,gujaratcricket,marketdhoom.com 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.
Subscribe to:
Posts (Atom)