<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    xiaoqiu369

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      7 Posts :: 3 Stories :: 2 Comments :: 0 Trackbacks

    2008年12月19日 #

    注: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 閱讀(238) | 評(píng)論 (1)編輯 收藏

    按照網(wǎng)上傳統(tǒng)的方法安裝幾次都沒有成功.最后只有下載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.從網(wǎng)上下載ferrect_ext.so文件,copy到 ferret-0.11.5-x86-mswin32\lib目錄(跟ferret.rb同一目錄)

    如果直接下載源碼安裝運(yùn)行ruby setup.rb.會(huì)出現(xiàn)"the c extensions could not be installed"的錯(cuò)誤


    手動(dòng)安裝plugins

    將下載的源文件放到vendor/plugins里面,進(jìn)入該目錄,運(yùn)行ruby install.rb

    出現(xiàn)的問題:

    => 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將這個(gè)文件放到lib里面.這個(gè)是200多K,而從網(wǎng)上下載的才30K.導(dǎo)致上面的問題.

    posted @ 2009-02-20 22:31 bobqiu 閱讀(956) | 評(píng)論 (0)編輯 收藏

    1.驗(yàn)證碼:recaptcha
    gem install --source http://www.loonsoft.com/recaptcha/pkg/ recaptcha

    2.搜索:acts_as_searchable是一個(gè)Rails插件,它依賴于Hyper Estraier這個(gè)獨(dú)立的搜索引擎所提供的索引和搜索服務(wù) 
                ferret gem install ferret -v=0.11.5 --platform mswin32  
    3.pdf:
    gem install pdf-writer  

    4.測(cè)試:
    RSpec+Mocha

    5.桌面應(yīng)用
    gem install anvil

    posted @ 2009-02-07 14:57 bobqiu| 編輯 收藏

    使用插件

    1/ will_paginate

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

     

    這個(gè)資料很多,不多說

     

    2/ squirrel

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

     

    主要實(shí)現(xiàn) 動(dòng)態(tài)條件的查詢,擴(kuò)展ActiveScaffold find方法。支持跨Model查詢,具體見

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

     

    貼段主要實(shí)現(xiàn)代碼

    #controller:

    def index

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

    #下面代碼可以按實(shí)際情況提取到Model或其他地方;方便測(cè)試我直接放在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>
        證書編號(hào) :<%= 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 閱讀(188) | 評(píng)論 (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 閱讀(140) | 評(píng)論 (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

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

    正在嘗試使用 URL E:\eclipse3.1.2\workspace\red51\fla\test51.swf 啟動(dòng)并連接到播放器
    解壓縮后字節(jié)數(shù)為 [SWF] E:\eclipse3.1.2\workspace\red51\fla\test51.swf - 2703
    Error #2044: 未處理的 NetStatusEvent:。 level=error, code=NetConnection.Connect.Failed
     at test51_fla::MainTimeline/test51_fla::frame1()[test51_fla.MainTimeline::frame1:1]


    解決辦法 :添加紅顏色部分代碼/

    var nc:NetConnection=new NetConnection();
    nc.connect("rtmp://localhost/red51");
    nc.objectEncoding=ObjectEncoding.AMF0;
    var so:SharedObject=SharedObject.getRemote("mo",nc.uri,false);
    nc.addEventListener(NetStatusEvent.NET_STATUS,netStatusEventHandle);

    function netStatusEventHandle(e:NetStatusEvent):void {
         trace(e.toString);
    }

    posted @ 2008-12-22 21:39 bobqiu 閱讀(1642) | 評(píng)論 (1)編輯 收藏

         摘要: call.fla:  1nc = new NetConnection();  2nc.connect("rtmp://localhost/red5");  3nc.onResult = function(obj) {  4    var ...  閱讀全文
    posted @ 2008-12-21 22:12 bobqiu 閱讀(1642) | 評(píng)論 (0)編輯 收藏

    Rails Routing from the Outside In
    http://guides.rails.info/routing_outside_in.html
    這篇文章將介紹Rails routing針對(duì)用戶方面的一些特性.參考這篇文章,你將會(huì)學(xué)到以下知識(shí):
    a.理解routing的作用
    b.破解routes.rb內(nèi)的代碼
    c.構(gòu)建你自己的routes,可以用classic hash樣式或現(xiàn)在流行的RESTful樣式.
    d.識(shí)別route怎樣與controller和action映射.

    1.The Dual Purpose of Routing

    Rails routing 有兩種機(jī)制,你可以將trees轉(zhuǎn)換為pager,或把paper轉(zhuǎn)換回trees.具體地說,它可以連接收到的請(qǐng)求與你應(yīng)用程序的控制器的代碼和幫你生成URLs,而不用做為一個(gè)字符串硬編碼.

    1.1connecting URLs to Code;
    當(dāng)你的應(yīng)用程序收到的請(qǐng)求為:
    GET /patients/17
    Rails里的路由引擎就是一段分發(fā)這個(gè)請(qǐng)求到應(yīng)用程序合適的位置進(jìn)行處理的一段代碼.在這個(gè)案例中,這個(gè)應(yīng)用程序很可能以運(yùn)行patients控制器里的show結(jié)束.顯示patients ID為17的詳細(xì)信息.

    1.2 Generateing URLs from Code
    Routing 也可以反過來運(yùn)行,如果你的應(yīng)用程序中包含這樣的代碼:

    @patient=Patient.find(17)
    <%= link_to "Patient Record",patient_path(@patient)%>

    這時(shí)路由引擎轉(zhuǎn)換這個(gè)鏈接到一個(gè)URL:http://example.com/patients/17.以這種方式你可以降低應(yīng)用程序的脆弱性,使你的代碼更加容易閱讀和理解.

    Patient 必須作為一個(gè)resource被聲明為一個(gè)資源,通過named route來轉(zhuǎn)換.

    2.Quick Tour of Routes.rb

    在Rails中routing有兩種組件,routing engine本身,它做為Rails的一部分,config/routes.rb文件,它包含實(shí)際的可用在應(yīng)用程序中的routes.

    2.1 Processing the File
    在形式上,Routes.rb文件也就是一個(gè)大大的block,會(huì)被放入ActionController::Routing::Routes.draw.
    在這個(gè)文件中有五種主要的樣式:
    RESTful Routes
    Named Routes
    Nested Routes
    Regular Routes
    Default Routes

    2.2 RESTful Routes
    RESTful Routes 利用rails嵌入式REST方法來將routing的所有信息包裝為一個(gè)單獨(dú)的聲明.eg: map.resource :books

    2.3 named Routes
    named routes 在你的代碼中給你很可讀的鏈接,也可以處理收到的請(qǐng)求

    map.login '/login' ,:controller=>'session',:action=>'new'

    2.4 Nested routes

    Nested routes可以在一個(gè)資源里聲明另一個(gè)資源.

    map.resources :assemblies do |assemblies|
     assemblies.resources :parts
    end

    2.5 Regular Routes
    map.connect 'parts/:number',:controller=>'inventory',:action=>'show'

    2.6 Default Routes
    map.connect ':controller/:action/:id'
    map.connect ':controller/:action/:id.:format'

    posted @ 2008-12-19 14:12 bobqiu 閱讀(228) | 評(píng)論 (0)編輯 收藏

    主站蜘蛛池模板: 亚洲AV噜噜一区二区三区| 亚洲av永久中文无码精品| GOGOGO免费观看国语| 免费国内精品久久久久影院| 亚洲精品无码人妻无码| 女人被免费视频网站| 亚洲日韩精品无码专区| aa级一级天堂片免费观看| 亚洲人成激情在线播放| 青青久在线视频免费观看| 亚洲综合av一区二区三区| 午夜免费福利影院| 久久亚洲色WWW成人欧美| 午夜国产大片免费观看| 边摸边吃奶边做爽免费视频网站| 一级毛片直播亚洲| 黄色片网站在线免费观看| 亚洲区不卡顿区在线观看| 任你躁在线精品免费| 久久久久亚洲精品无码蜜桃| 97精品免费视频| 91丁香亚洲综合社区| 国产在线观看免费完整版中文版| 成人在线免费视频| 国产亚洲人成无码网在线观看| 久久精品一本到99热免费| 亚洲欧洲另类春色校园网站| 国产午夜免费福利红片| 中文字幕永久免费| 午夜免费福利影院| 一级人做人a爰免费视频| 亚洲国产香蕉碰碰人人| 国产精品成人69XXX免费视频| 国产亚洲精AA在线观看SEE| 中文字幕免费在线看线人| 国产午夜亚洲精品午夜鲁丝片| 免费人成在线观看网站| 亚洲色少妇熟女11p| 亚洲午夜国产精品无码老牛影视| 久久WWW免费人成一看片| 特级无码毛片免费视频|