Star
Monthly Archives: March 2012
星级评价的实现方法
html:
<ul id=“start-selection” class=“star clearfix”>
<li><a href=“javascript:void(0);”>★</a></li>
<li><a href=“javascript:void(0);”>★</a></li>
<li><a href=“javascript:void(0);”>★</a></li>
<li><a href=“javascript:void(0);”>★</a></li>
<li><a href=“javascript:void(0);”>★</a></li>
</ul>
<%= f.hidden_field :star, :value => “” %>
stylesheet:
/* —– .clearfix —– */
.clearfix:after {
content: “.”;
display: block;
clear: both;
height: 0;
visibility: hidden;
}
.clearfix {
min-height: 1px;
}
* html .clearfix {
height: 1px;
}
/* —– review —– */
.star img{
vertical-align:text-top
}
ul.star{
margin:0;
}
ul.star li{
float:left;
display:inline;
width:16px;
height:15px;
background:url(/assets/icon_star.gif) no-repeat;
text-indent:-9999px;
margin-right:3px;
}
ul.star li a{
width:16px;
height:15px;
background:url(/assets/icon_star.gif) no-repeat;
display:block;
overflow:hidden;
}
ul.star li a:hover{
background-position:right;
}
javascript:
$(function(){
$(’#start-selection a’).each(function(index){
$(this).click(function(){setStar(this,index);return false;});
});
//alert($(’#review_star’).val());
if($(’#review_star’).val()){
setStar(null,$(’#review_star’).val()-1);
}
}
);
function setStar(obj,index){
//alert(index);
$(’#review_star’).val(index+1);
$(’#start-selection a’).each(function(i){
if(i<=index){
$(this).css(“background-position”,“right”);
}else{
$(this).css(“background-position”,“left”);
}
})
}
赋予terminal之美学
今天把我的terminal打扮一下,装了几个实用的插件。
参考:
http://railscasts-china.com/episodes/7-rails-with-vim
这样开发Rails项目便利多了。
关于 ctags 的特殊注意
从 http://www.vim.org 下载 ctags.vim 并拷贝到 ~/.vim/plugin 下之后,
执行
sudo apt-get install ctags
在项目下执行
ctags -R –exclude=.git –exclude=log * –exclude=coverage
生成了 tags 文件。在方法处用 Ctrl + ] 前往方法体。
zsh
需要注意的是按照说明配置后,如果你已经安装了rvm,那么你用“rvm list”这样的命令会提示:
zsh: correct ‘rvm’ to ‘rvim’ [nyae]?
这时你需要在~/.zshrc中添加如下一行:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
ack.vim安装完执行“:Ack [keyword]”查找时如果提示:
zsh|1| command not found: ack
执行这句:
sudo ln -s /usr/bin/ack-grep /usr/local/bin/ack
[Rails]在/test/fixtures下添加测试数据的方法
比如users.yml
(users.yml文件是执行rails g model user自动生成的,文件名对应表名)
user1:
name: user1
age: 10
user2:
name: user2
age: 20
user3:
name: user3
age: 30
在控制台执行命令:
rake db:fixtures:load FIXTURES=users
如果用
rake db:fixtures:load
就执行所有的fixtures文件
※在development、test、production环境中都可用。
[Ruby]顺序处理数组和哈希的所有元素
# 数组的时候
array = [1, 2, 3]
array.each do |elem|
p elem
end
#=> 1
#=> 2
#=> 3
# 哈希的时候
hash = {“Perl”=>1, “Python”=>2, “Ruby”=>3}
hash.each do |key, value|
p [value, key]
end
Ruby 1.8:
#=> [3, Ruby]
#=> [1, Perl]
#=> [2, Python]
Ruby 1.9:
#=> [1, Perl]
#=> [2, Python]
#=> [3, Ruby]
※Ruby 1.8顺序不一定,Ruby 1.9一定按生成的顺序处理。