Welcome 微信登录

首页 / 软件开发 / JAVA / 建立一个典型的Ruby On Rails网站(四)

建立一个典型的Ruby On Rails网站(四)2011-12-08 javaeye 夜鸣猪缓存和页面显示,这是最后一个部分了,真没想到一个连载竟然用了几个小时。累了...

外部链接和跟踪

如果想对外部网站资源进行链接和跟踪,可以使用如下的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