`

建立一个典型的RubyOnRails网站(四)

 
阅读更多

 缓存和页面显示,这是最后一个部分了,真没想到一个连载竟然用了几个小时。累了...

  外部链接和跟踪

  如果想对外部网站资源进行链接和跟踪,可以使用如下的helper方法:

  Ruby代码  

  external_link_to(text,url)
  external_link_to(image_tag(image),url)

  这两种生成链接的方法(一种是文字链接,一种是图形链接)都可以对链接情况进行日志记录。如果将environment.rb文件中的$USE_EXTERNAL_LINK_POPUPS 参数设置为真,外链接将一弹出框形式存在。下面的参数可以传递给Url

  Ruby代码  

  :new_window=>true or false -- determines if link appears in new browser window (defaults to true)
  :show_only_if_link=>true or false -- determines if image or text is shown if no URL was supplied (defaults to false)
  :show_link_icon=>true or false -- determines if the external icon image is shown after the link (defaults to true for text links and false for image links)

  对于图形,可以传递如下参数:

  Ruby代码   

  :alt=>'value' -- alt tag is set with the value passed
  :title=>'value' -- title tag is set with the value passed

  对于当前来说,还没有提供对外部链接跟踪情况的报表。所有的链接跟踪情况通过 "external_link_logs" 数据库进行存储。

  部分缓存机制

  部分缓存功能需要配置文件设置,才能启用(config/production.rb)并且要打开存储机制

 如下:

  Ruby代码 

   
  config.cache_store = :mem_cache_store, '10.0.0.1:11211', '10.0.0.2:11211'

  缓存设置如下:

  Ruby代码   

 config.action_controller.perform_caching             = true

  静态页面首先将被缓存。主页面的缓存周期是一个小时。或者通过  config/environment.rb文件的 $CACHE_CLEAR_IN_HOURS 参数定义

  头文件和导航栏的缓存通过动态的部分缓存,当改变的时候进行清除。

  搜索功能的缓存,依赖与检索类序,语言,和是否有审查的状态,进行缓存。

  当用户用管理员或内容合伙人登录的时候,页面将不进行缓存。

  进行缓存的项目如下:

  Ruby代码  

- taxon_id
- language
- expertise level
- vetted or all information
- default taxonomic browser
- curator for page

  页面缓存的过期,可以通过手动或服务器定时调用如下地址实现:  They only work if called

  Ruby代码 

  localhost:3000/expire_all    # expire all non-species pages
  localhost:3000/expire_taxon/TAXON_ID  # expire specified taxon ID (and it's ancestors)
  localhost:3000/expire_taxa/?taxa_ids=ID1,ID2,ID3 # will expire a list of taxon IDs (and their unique ancestors) specified in the querystring (or post) parameter "taxa_ids" (separate by commas)
  localhost:3000/clear_caches # expire all fragment caches (if supported by data store mechanism)
 对于应用程序内容,可以通过如下方法调用实现。

  Ruby代码  

  expire_all   # expire all non-species pages
  expire_taxon(taxon_ID)  # expire specified taxon id and ancestors (unless :expire_ancestors=>false is set)
  expire_taxa(taxon_ID_array)# expire specified array of taxon ID and unique ancestors (unless :expire_ancestors=>false is set)
  clear_all_caches # expire all fragment caches (everything!)

  页面显示插件ASSETT PACKAGER

  (CSS and JS)

  asset_packager 插件的详细介绍, 可以参考 http://synthesis.sbecker.net/pages/asset_packager

  如果你想在自己项目中引入一个javascript文件,那么你需要编辑"config/asset_packager.yml"文件 并且需要按照加载的顺序放置。项目通过一个Rake任务对Css和Js文件管理和组合需要指出的是,在config文件中Js文件的顺序要和组合时的顺序一致。

  当更新Js/Css代码后,要通过rake 任务进行更新。

  如下:

  Ruby代码  

  rake asset:packager:build_all

  在产品模式下,这个rake命令是做为capistrano部署命令的一部分。

  做为测试目的,你也可以强制在config/environments/development.rb" 或 "config/environment.rb"中增加

  Ruby代码

  Synthesis::AssetPackage.merge_environments = ["development", "production"]

  控制台属性

  1. 通过ConceptID看属性

  Ruby代码  

     t=TaxonConcept.find(101)

  2. 查询等级

  Ruby代码   

     he_all=t.hierarchy_entries  OR  he=t.entry (for the default)

  3. 查询相关等级

  Ruby代码   

      h=he_all[0].hierarchy #   OR  h=he.hierarcy
      h.label
      h.agent.full_name
      h.agent.hompage
      h.agent.logo_cache_url

  4. 查询相关等级的agents

  Ruby代码   

agents=he[0].agents  # OR  agents=he.agents
        agents.each {|agent| puts agent.full_name + " " + agent.homepage + " " + agent.logo_cache_url}

  文档

  项目并不是通过svn repo来产生文档。所以,用户需要如下得到:

  Ruby代码  

  template=`allison --path` rake doc:reapp

  写在最后:

   终于写完了,还是比较有收获的。

<!-- 分页 -->
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics