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

ruby>>
class Posts < Application
before_render :set_title1, :only => :show
before :set_title2, :only => :show

def show(id)
@post = Post.get(id)
display @post
end

private
def set_title1
@title = @post.title # <= you can access to @post here
end

def set_title2
@title = @post.title #=> @post is nil!
end
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 takiuchi takiuchi on Sun 1 Feb 2009 at 10:08 with 0 comments