Friday, June 25, 2010
Wednesday, June 16, 2010
Select/Un Select check boxes with javascript
view:
<%=check_box_tag :id => "select_all" %>
User List
<% @users.each do |user| %>
<%=check_box_tag "recipient[]", :value => "user.email" %>
<% end %>
javascript code:
script type ="text/javascript">
$(function(){
$("#select_all").click(function(){
$flag = $(this).attr('checked');
if ($flag) {
$("input[name='recipient[]']").each(function(){
$(this).attr('checked', true)
});
}else{
$("input[name='recipient[]']").each(function(){
$(this).attr('checked', false)
});
}
});
});
<%=check_box_tag :id => "select_all" %>
User List
<% @users.each do |user| %>
<%=check_box_tag "recipient[]", :value => "user.email" %>
<% end %>
javascript code:
script type ="text/javascript">
$(function(){
$("#select_all").click(function(){
$flag = $(this).attr('checked');
if ($flag) {
$("input[name='recipient[]']").each(function(){
$(this).attr('checked', true)
});
}else{
$("input[name='recipient[]']").each(function(){
$(this).attr('checked', false)
});
}
});
});
Rails dynamic layout selection
controller:
class MyController < ApplicationController
layout :check_layout
private
def check_layout
return current_user.admin? ? "admin" : "application"
# current_user is user who logged in
end
end
class MyController < ApplicationController
layout :check_layout
private
def check_layout
return current_user.admin? ? "admin" : "application"
# current_user is user who logged in
end
end
Monday, June 7, 2010
Multiple Ruby versions in Windows
Multiple ruby versions in windows can possible with "http://github.com/vertiginous/pik">Pik
Install gem gem install pik;
After the gem is installed, you can use the ‘pik_install’ script to install the pik executable. Install pik to a location that’s in your path, but someplace other than your ruby\bin dir.
Path
For instance, the directory C:\Pik is in my path:
Set the path in 'Environment variables' like
>path PATH=C:\Pik;C:\Program Files\Windows Resource Kits\Tools\;c:\ruby\Ruby-186-p383\bin;
Install gem gem install pik;
After the gem is installed, you can use the ‘pik_install’ script to install the pik executable. Install pik to a location that’s in your path, but someplace other than your ruby\bin dir.
Path
For instance, the directory C:\Pik is in my path:
Set the path in 'Environment variables' like
>path PATH=C:\Pik;C:\Program Files\Windows Resource Kits\Tools\;c:\ruby\Ruby-186-p383\bin;
Subscribe to:
Posts (Atom)