xiaoqiu369

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  7 Posts :: 3 Stories :: 2 Comments :: 0 Trackbacks

2009年2月7日 #

注:rails的版本是2.0以上.

1.在application.rb里添加分页信息方法:

1 def page_for(result,options={})
2 
3       default_options = {:per_page => 10}   
4        options = default_options.merge options   
5        pages = WillPaginate::Collection.new(options[:page],options[:per_page],result.total_hits)   
6         return pages
7     
8     end
2.users_controller.rb里添加search方法:
 1   def search
 2     
 3     @keyWord=params[:keyWord]
 4     if params[:page]==nil||params[:page]==""
 5       @page=1
 6     else
 7       @page=params[:page]
 8     end
 9     @users=User.find_by_contents(@keyWord,:per_page=>2,:page=>@page)
10     @pages=page_for(@users,:page=>@page,:per_page=>2)
11   end
3.view页面:
 1 <%@users.each do |user|%>
 2 <br>
 3    username: <%=user.highlight(@keyWord,:field=>:user_name,:num_excerpts=>1,:pre_tag=>'<strong>',:post_tag=>'</strong>')%><br> 
 4    地址:<%=user.highlight(@keyWord,:field=>:introduce,:num_excerpts=>1,:pre_tag=>'<strong>',:post_tag=>'</strong>')%>
 5 ==================================================================================
 6 <%end%>
 7 <p>
 8   共<%=@users.total_hits%>条记录
 9 </p>
10 <p>
11   <%=link_to "上一页",{:page=>@pages.previous_page,:keyWord=>@keyWord} %>
12 <%=link_to "下一页",{:page=>@pages.next_page,:keyWord=>@keyWord} %>
13 <br/>
14 <%=will_paginate @users%>
15 </p>
posted @ 2009-03-04 20:00 bobqiu 阅读(227) | 评论 (1)编辑 收藏

按照网上传统的方法安装几次都没有成功.最后只有下载gem文件安装
1.下载ferret-0.11.6-mswin32.gem文件
2.用gem 安装:gem install ferret-0.11.6-mswin32 --local
3.gem install acts_as_ferret
4.从网上下载ferrect_ext.so文件,copy到 ferret-0.11.5-x86-mswin32\lib目录(跟ferret.rb同一目录)

如果直接下载源码安装运行ruby setup.rb.会出现"the c extensions could not be installed"的错误


手动安装plugins

将下载的源文件放到vendor/plugins里面,进入该目录,运行ruby install.rb

出现的问题:

=> Booting WEBrick...

c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:442:in `load_missing_constant': uninitialized constant Ferret::Analysis::Analyzer (NameError)

        from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in `const_missing'

        from E:/rorapp/demo/vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb:17

        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'

        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'

        from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'

        from E:/rorapp/demo/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:28

        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'

        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'

         ... 25 levels...

        from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49

        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'

        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'

        from script/server:3

 解决办法就是把上面安装完成ferret后的文件里找到ferrect_ext.so将这个文件放到lib里面.这个是200多K,而从网上下载的才30K.导致上面的问题.

posted @ 2009-02-20 22:31 bobqiu 阅读(938) | 评论 (0)编辑 收藏

1.验证码:recaptcha
gem install --source http://www.loonsoft.com/recaptcha/pkg/ recaptcha

2.搜索:acts_as_searchable是一个Rails插件,它依赖于Hyper Estraier这个独立的搜索引擎所提供的索引和搜索服务 
            ferret gem install ferret -v=0.11.5 --platform mswin32  
3.pdf:
gem install pdf-writer  

4.测试:
RSpec+Mocha

5.桌面应用
gem install anvil

posted @ 2009-02-07 14:57 bobqiu| 编辑 收藏