will_paginate and ajax in rails 3

在rails3项目中出现分页内容不能加载Ajax情况,开始以为是升级rails 3的插件问题,记录一下解决办法。
1.view 显示层(如ask/show.html.erb)
< div id="queue"> < %= render :partial => ‘queue’ %>
< script>
$(document).ready(function() {
$(‘.pagination a’).attr(‘data-remote’, ‘true’);
});

2.controller (如ask_controller.rb)

def show
@user = User.find(params[:id])
@queue_items = @user.queue_items.with_state(:pending).paginate(:page => params[:queue_page] || 1, :per_page => 1)
respond_to do |format|
format.html
format.js
end
end

3.js template

$(‘#queue’).html(‘< %=escape_javascript render :partial => “queue” %>’);
$(‘.pagination a’).attr(‘data-remote’, ‘true’);

还有一种在Rails3中的方法也一并记录如下。(via:火哥的零碎)

class RemoteLinkRenderer < WillPaginate::ViewHelpers::LinkRenderer
def prepare(collection, options, template)
@remote = options.delete(:remote) || { }
super
end

def link(text, target, attributes = {})
if target.is_a? Fixnum
attributes[:rel] = rel_value(target)
target = url(target)
end
attributes[:href] = target
# page_attr = { :page => target }
@template.link_to( text.to_s.html_safe, target, :remote => true )
end
end

2008年4月18日

去不去家乐福,这已经成为了最近网络上人人要表态的话题。晚上和几位老师也聊了很多,能理解大家的这种抵制情绪,当共同利益受损时迫切地想要寻找一种伤害者看得到的方式,来表明自己的姿态。在西藏问题上,涉及的因素太多,多听听不同的声音,多去思考。这样才能找到问题的根本,找到应对的办法。
当看到”武汉家乐福的柜台被砸得一塌糊涂,看到一条留言说:最后,收拾残局的,还是一群月薪800元的家乐福中国职员。 “,当看到金晶,一个几天前还是“民族英雄,最美的女神”,却因为说了 不赞成抵制法国家乐福 的话,就被批为汉奸。这就是爱国的表达形式吗?我只想建议在”抵制”之前稍微使用一下自己的智商,冷静的理性的对待,这样下去抵抗西方没实现反而自己人和自己人先掐起脖子来……

Posted by in 读书

Tags:

Permalink 1 Comment

海底光缆修复了?

从昨天开始,不用代理也能正常访问我的BLOG了。且其它一此国外网站都可以访问,看来经过一个月的等待不用再忍受龟速一样的网络了。(具体是否开通也没听到电信的说法,只能通过这几点做的判断吧)
人有时候就是这样,什么东西失去了,才知道它的好。因为这次的海底光缆中断,导致许多国外的网站及服务无法使用,我想有不少人都会得上地震后遗症的。也只有这个时候我们才知道这条细细的连通世界的光缆有多么重要。
这次的电信部门不知道干嘛去了,这么大个表彰的机会也放弃了,可惜呀,实在可惜了……
就像FENNG说的:“上帝说,网络通。就通; 上帝说,没时间修。那么用户就只有等; 上帝说,好了我也不告诉你。我们就不知道。”

上周我的这个BLOG已经升级到Wordpress2.1版本,由于网络的原因很多插件及需要修改的东西没有来得及修正。这段时间有必要将之做一次全面的调整及优化,同时BLOG也会正常更新…….

Happy blogDay 2006

今天是BlogDay!国内相关的文字很少,我也是看到这篇文章才想起8月31日这个日子。

什么是BlogDay
BlogDay 起源于博客们(Bloggers)认为自己应该有一个专属的节日,用以认识其它来自于不同国度或拥有各种不同嗜好、兴趣的博客。在 BlogDay当天,所有参与活动的博客们应该在自己的站上推荐五个具有特色的博客(Blogs)给所有来访的朋友,藉此和大家分享更多崭新而有趣的博客。

谁提出BlogDay
你有否注意日期3108(8月31日)这样的写法看起来很像“Blog”这个词。是的,Nir Ofir首先在以色列的一次Blog会议上一边涂鸦一边发现到这个象形,并由此产生出将象形与节日结合的创意,设立一个庆祝日——Blogday,作为博客群体的节日,甚至希望它能成为今后全球的传统节日。这个创意不亚于n年前同样因创意而诞生的Blog,而且创意者的本意不仅仅是单纯设立一个节日,而是号召大家在8月31日这一天都发表一篇网志,让人们发现一些优秀的Blog,并相互推广。

在BlogDay做什么
在八月三十一日这一天内,全世界参与活动的网民都会发表一篇帖子推荐五个新颖的博客,而且最好这五个部落格的内容可能是来自不同的文化、观点和型态。而所有造访的朋友都可以在八月三十一日当天发现自己前所未知的博客,藉此认识更多博客并为这些新发现而庆祝。

1. 找出五个你觉得有趣的新鲜博客。
2. 在2005年的BlogDay当天,留言给这五位博客的主人,告知你推荐了他们的博客。
3. 为推荐的博客写下简短的介绍,并在文中放置这些链结。
4. 在8月31日当天张贴上推荐的帖子。5. 並且加上BlogDay的標籤(Tag): http://technorati.com/tag/BlogDay2006/ ,同時連結到BlogDay 官方網站http://www.blogday.org/

这是个特别的日子,是我们所有BLOGGER共同的节日,写下此文时已经是8.31:2点45分了,没有做什么准备不打算做推荐了,就以此文和众BLOGER同庆吧。
BTW:不知道BLOGDAY是怎么了,打开时出现Error establishing a database connection的错误….

Aboslute 布局暂存….

暂存,待整理!
定义座标作为限制(x,y) and (w,h) coordinates:
[CODE_LITE]
private int x, y, width, height;

public static final int ADAPT = -1;

public XYConstraints(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
[/CODE_LITE]
适应常数可能被使用为宽度和高度以便布局经理使用宽度并且高度定义由组分(got from get…..Size()).必须实施LayoutManager2 和所有方法被定义:
首先我们假设我们的布局不需要任何特别对准线, 对上部左角落总将被排列:
[CODE_LITE]
public float getLayoutAlignmentX(Container arg0) {
return 0;
}

public float getLayoutAlignmentY(Container arg0) {
return 0;
}
[/CODE_LITE]
1) 审阅所有分组和增加他们的X 和W 座标和Y 和H 座标。
2) 如果分组使用适应常数, 使用对应的方法在分组(得到..大小) 。
[B]E.g. the getPreferredSize method:[/B]
[CODE_LITE]
public Dimension preferredLayoutSize(Container arg0) {
int rightBound = 0;
int bottomBound = 0;

for (Iterator iter = constraints.keySet().iterator(); iter.hasNext();) {
Component comp = (Component) iter.next();
XYConstraints constraint = (XYConstraints) constraints.get(comp);
Dimension size = comp.getPreferredSize();
int width = constraint.getWidth();
if (width == XYConstraints.ADAPT) {
width = size.width;
}
if ((constraint.getX() + width) > rightBound) {
rightBound = constraint.getX() + width;
}
int height = constraint.getHeight();
if (height == XYConstraints.ADAPT) {
height = size.height;
}
if ((constraint.getY() + height) > bottomBound) {
bottomBound = constraint.getX() + height;
}
}
return new Dimension(rightBound, bottomBound);
}
[/CODE_LITE]
因为我们不存储什么, 我们不需要实施其它的invalidateLayout:
[CODE_LITE]
public void invalidateLayout(Container arg0) {
// No information cached
}
[/CODE_LITE]
现在我们来到有趣的部份,首先我们需要实施方法增加分组以限制来布局。
有二个方法: 一以限制代表作为对象和其他作为串。 串一个, 我们将解码串对对象和将要求第一方法:
[CODE_LITE]
public void addLayoutComponent(String constraintString, Component component) {
XYConstraints constraint = new XYConstraints(0, 0, XYConstraints.ADAPT, XYConstraints.ADAPT);
String[] args = constraintString.split(“;”);
for (int i = 0; i
暂存,待整理!
定义座标作为限制(x,y) and (w,h) coordinates:
[CODE_LITE]
private int x, y, width, height;

public static final int ADAPT = -1;

public XYConstraints(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
[/CODE_LITE]
适应常数可能被使用为宽度和高度以便布局经理使用宽度并且高度定义由组分(got from get…..Size()).必须实施LayoutManager2 和所有方法被定义:
首先我们假设我们的布局不需要任何特别对准线, 对上部左角落总将被排列:
[CODE_LITE]
public float getLayoutAlignmentX(Container arg0) {
return 0;
}

public float getLayoutAlignmentY(Container arg0) {
return 0;
}
[/CODE_LITE]
1) 审阅所有分组和增加他们的X 和W 座标和Y 和H 座标。
2) 如果分组使用适应常数, 使用对应的方法在分组(得到..大小) 。
[B]E.g. the getPreferredSize method:[/B]
[CODE_LITE]
public Dimension preferredLayoutSize(Container arg0) {
int rightBound = 0;
int bottomBound = 0;

for (Iterator iter = constraints.keySet().iterator(); iter.hasNext();) {
Component comp = (Component) iter.next();
XYConstraints constraint = (XYConstraints) constraints.get(comp);
Dimension size = comp.getPreferredSize();
int width = constraint.getWidth();
if (width == XYConstraints.ADAPT) {
width = size.width;
}
if ((constraint.getX() + width) > rightBound) {
rightBound = constraint.getX() + width;
}
int height = constraint.getHeight();
if (height == XYConstraints.ADAPT) {
height = size.height;
}
if ((constraint.getY() + height) > bottomBound) {
bottomBound = constraint.getX() + height;
}
}
return new Dimension(rightBound, bottomBound);
}
[/CODE_LITE]
因为我们不存储什么, 我们不需要实施其它的invalidateLayout:
[CODE_LITE]
public void invalidateLayout(Container arg0) {
// No information cached
}
[/CODE_LITE]
现在我们来到有趣的部份,首先我们需要实施方法增加分组以限制来布局。
有二个方法: 一以限制代表作为对象和其他作为串。 串一个, 我们将解码串对对象和将要求第一方法:
[CODE_LITE]
public void addLayoutComponent(String constraintString, Component component) {
XYConstraints constraint = new XYConstraints(0, 0, XYConstraints.ADAPT, XYConstraints.ADAPT);
String[] args = constraintString.split(“;”);
for (int i = 0; i

Recent Comments