xiaoqiu369

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

          2008年12月23日 #

          注: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 閱讀(237) | 評論 (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 閱讀(955) | 評論 (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| 編輯 收藏

          使用插件

          1/ will_paginate

              http://groups.google.com/group/will_paginate

           

          這個資料很多,不多說

           

          2/ squirrel

              下載:http://github.com/thoughtbot/squirrel/tree/master

           

          主要實現 動態條件的查詢,擴展ActiveScaffold find方法。支持跨Model查詢,具體見

              說明:http://thoughtbot.com/projects/squirrel

           

          貼段主要實現代碼

          #controller:

          def index

          #######################################################

          #下面代碼可以按實際情況提取到Model或其他地方;方便測試我直接放在index下

          #######################################################
              @permissions = Permission.find(:all) do
                paginate :page => params[:page]||1,:per_page=>5
                any do
                  name == params[:permission][:name] unless params[:permission].nil?
                  code == params[:permission][:code] unless params[:permission].nil?
                  permit_date == params[:permission][:permit_date] unless params[:permission].nil?
                  contact.company == params[:contact][:company] unless params[:contact].nil?
                end
              end
           #######################################################
              respond_to do |format|
                format.html # index.rhtml
                format.xml  { render :xml => @permissions.to_xml }
              end
            end

           

           

          #index--view

           

          <% field_set_tag do %>
            <% form_for :permission, :url=>permissions_url,:method=>:get,:html=>{:method=>:get} do |f| %>
              公司名稱 :<%= text_field_with_auto_complete :contact, :company,{},{:method=>:get}%>  <br>
              證書類型 :<%= text_field_with_auto_complete :permission, :name,{},{:method=>:get}%>  <br>
              證書編號 :<%= text_field_with_auto_complete :permission, :code,{},{:method=>:get}%>  <br>
              授與日期 :<%= text_field_with_auto_complete :permission, :permit_date,{},{:method=>:get}%>  <br>
              <%= submit_tag '查詢'  %>
             <% end %>
          <%  end %>

           

          ...

           

          <div class="digg_pagination">
            <div clas="page_info">
              <%= page_entries_info @permissions %>
            </div>
            <%= will_paginate @permissions, :container => false %>
          </div>

          posted @ 2009-01-19 11:23 bobqiu 閱讀(187) | 評論 (0)編輯 收藏

              1.we receive a new request for a page to our rails application.
              2.Rails routes this request to a controller for processing.
              3.Our controller interacts with the models in our application to gather the necessary data
              4.Our model may retrive or insert data to our database
              5.Once our models have generated or retrived correct information,they return the data back to the collection
              6.The controller collects all of the data it's received from models and selects a view template to render
              7.The view template is rendered using  the data that the collection gathered and handed to  the web server
              8.An html page is returned to the user.
          posted @ 2009-01-05 16:18 bobqiu 閱讀(138) | 評論 (0)編輯 收藏

          按照慣例,還是打印出Hello world.

          /app/controllers/stories_controllers.rb:

          class StoriesController<ActionControllers::Base
              def index
                  @varies="hello world"
              end
          end


          /views/stories/index.html.erb:

          <%=@varies%>

          /config/routes.rb

          ActionController::Routing::Routes.draw do |map|
              map 'stories',:controller=>'stories',:action=>'index'
          end

          啟動服務在IE中打開:
          http://localhost:3000/stories
          OK
          posted @ 2008-12-23 16:46 bobqiu 閱讀(175) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 铜川市| 溆浦县| 茂名市| 隆子县| 和林格尔县| 广灵县| 台东县| 东平县| 琼结县| 青铜峡市| 仁化县| 英山县| 获嘉县| 武胜县| 吴旗县| 比如县| 自贡市| 湛江市| 百色市| 余姚市| 唐山市| 平塘县| 新建县| 基隆市| 江津市| 柳林县| 都江堰市| 巴东县| 芷江| 肥东县| 保山市| 迁西县| 永泰县| 达孜县| 福鼎市| 岗巴县| 潼关县| 杂多县| 敦煌市| 永靖县| 都安|