Vesioning your Rails app without edgeRails

If you are bothered by switching between different versions Rails, like me, here is a straightforward way to do it:

1. Know what versions you have

gem list rails

1. Install specified version of Rails ( I will take rails v2.0.2 for example)

gem install rails -v 2.0.2

2. Use specified version of Rails to create a project. ( Pay attention to the leading and trailing "_")

rails _2.0.2_ projectName


The new outlooking

I noticed some small but interesting changes to the MSN space: Ads banner is removed,  font is enlarged, personal badge is crystallized…  Good, I like them.

How exactly Rails routing works?

Translation is a good way to force yourself understand the thing you want to know. Here is a great explanation of how routing works from "The Rails Way", well worth a translation.

What Happened to :id?
Note that in that last example, we defaulted on :controller but we had to provide a value for :id. That’s because of the way defaults work in the url_for method. What happens is that the route generator marches along the template segments, from left to right—in the default case like this:
And it fills in the fields based on the parameters from the current request until it hits one where you’ve provided a value:
default!                   provided!
When it hits one that you’ve provided, it checks to see whether what you’ve provided is the default it would have used anyway. Since we’re using a show template as our example, and the link is to an edit action, we’re not using the default value for :action.
Once it hits a non-default value, url_for stops using defaults entirely. It figures that once you’ve branched away from the defaults, you want to keep branching. So the nondefault field and all fields to its right cease to fall back on the current request for default values.
That’s why there’s a specific value for :id, even though it may well be the same as the params[:id] value left over from the previous request.
Pop quiz: What would happen if you switched the default route to this?
map.connect ‘:controller/:id/:action’
And then you did this in the show.rhtml template:
<%= link_to "Edit this auction", :action => "edit" %>
Answer: Since :id is no longer to the right of :action, but to its left, the generator would happily fill in both :controller and :id from their values in the current request. It would then use "edit" in the :action field, since we’ve hard-coded that. There’s nothing to the right of :action, so at that point everything’s done.


需要注意的是在前面的例子中,我们对:controller使用默认,但是却给:id赋了值。这是由于url_for方法对于默认情况的处理的需要。事实上,route generator从左到有的处理字段。对于默认字段,route generator从当前request的参数中提取信息填写到相应的字段,一直到用户提供的值的字段(非默认)停止:



当route generator遇到用户赋值,它会忽略默认而使用用户提供的信息。在我们这个例子中:controller因为没有用户赋值而使用默认,而:action则使用用户提供的"edit"。

一旦route generator遇到不能使用默认的字段,url_for就完全停止使用默认。route generator认为一旦用户开始使用非默认的信息,就会一直这样继续下去,所以从第一个非默认字段向右的所有字段都不会向当前request请求默认信息。


提问:如果将现在的默认route改成map.connect ‘:controller/:id/:action’,在show.rhtml中使用<%= link_to "Edit this auction", :action => "edit" %>会怎样?

回答:由于非默认字段在最右边,route generator会使用默认信息填写:controller和:id字段。