在plugin中增加route

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# add a route for favor
class ActionController::Routing::RouteSet 
  class_eval <<-"end_eval", __FILE__, __LINE__  
      alias draw_without_act_as_favor draw
      def draw_with_act_as_favor
        draw_without_act_as_favor do |map|
          map.resources :favors
          yield map
        end
      end
      alias draw draw_with_act_as_favor
  end_eval
end 


#本来也可以这样添加
ActionController::Routing::Routes.draw do |map|
  map.connect ':controller/:action/:id'
end

#但是draw的定义如下,会清空draw方法调用之前的routes。
def draw
  clear!
  yield Mapper.new(self)
  named_routes.install
end

在init.rb中增加这些代码。从fckeditor插件中偷来的

    Posted by holin At May 16, 2008 16:56

请登录以发表评论。