ITeye博客

ruby on rails 实现按首字母搜索。A..Z

PBFox · 2007-09-12 11:08 · Markdown

helper:

def alphabet_index(url)
output=""
('A'..'Z').each do |alpha|
output << <<-EOF
#{link_to_remote(alpha, :update=>'table',:url=>{:action=>url,:id=>alpha})}
EOF
end
output
end

controller:

def sort_alphabet
alpha=params[:id]
condition=['title LIKE ? "%"',alpha]
@materials=Material.find(:all,:conditions=>condition)
if request.xml_http_request?
render(:partial=>"materials_list",:layout=>false)
end
end

view:

<div class="alphabet"><%=alphabet_index("sort_alphabet")%></div>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。