Forum: Ruby on Rails rendering in after_filter

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Esad H. (Guest)
on 2006-05-11 21:15
Hi!

Is it possible to render the action within the after_filter method, or
is the rendering performed before?

I have something like this:

class FooController
  after_filter :send
  def a
    @content=...
  end

  def b
    @content=..
  end
protected
  def send
    send_data(@content,...)
  end
end

However, when calling the action a or b, the @content doesn't get sent,
but instead rails shows an error message abour missing template.
Bob H. (Guest)
on 2006-05-12 19:55
(Received via mailing list)
Hi,


On May 11, 2006, at 1:15 PM, Esad H. wrote:

>     @content=...
>
> However, when calling the action a or b, the @content doesn't get
> sent,
> but instead rails shows an error message abour missing template.

Here's a bit of guessing...

The response body already has the content by the time the filter is
run, well, it does by the time the around filters are run so I assume
the after filters too. So I'd guess that rails is looking for its
response content before the filters are run -- this makes sense since
the after filters are supposed to have access to whatever is being
returned. Try adding a 'return false' at the end of the a and b
methods -- if that doesn't stop the template error then something
else is wrong. The send_data may still not work from the filter, if
it doesn't, try writing "response.body = @content" (and you'll have
to get the headers setup properly as well). (note that if you are
using around filters the controller is the argument and you write
something like: "controller.response.body = controller.content" so
make sure that the @content attribute is visible).

Cheers,
Bob

>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails

----
Bob H.                  -- blogs at <http://www.recursive.ca/
hutch/>
Recursive Design Inc.          -- <http://www.recursive.ca/>
Raconteur                      -- <http://www.raconteur.info/>
xampl for Ruby                 -- <http://rubyforge.org/projects/xampl/>
This topic is locked and can not be replied to.