• 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
  • 28

I made a simple plugin to explain a concept of render-filters.

merb_render_filter

In your controller,

   1  class Posts < Application
   2    before_render :set_title1, :only => :show
   3    before :set_title2, :only => :show
   4  
   5    def show(id)
   6      @post = Post.get(id)
   7      display @post
   8    end
   9  
  10  private
  11    def set_title1
  12      @title = @post.title # <= you can access to @post here
  13    end
  14  
  15    def set_title2
  16      @title = @post.title #=> @post is nil!
  17    end
  18  end

Without this plugin, you couldn't access to instance variables from before-filters. Of course you can prepare @post in the first before-filter so that you can access from other before-filters. But why Merb has the action-args? They are ignored in such case. This was the problem I wanted to solve by the plugin.

posted by Png takiuchi on Sun 1 Feb 2009 at 10:19

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1263
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ