After_filter and partials

Hello !

I’d like to use a filter to add something like the following script to
all views rendered by my application :

The goal is to update a div with some flash content, systematically,
without needing to write code in every view or method.

I don’t know how to proceed with filters, how to access to the repsonse
body and to change it…

If anybody could help …

thanks

You dont need a filter, you need a layout

http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html

nico Itkin wrote:

Hello !

I’d like to use a filter to add something like the following script to
all views rendered by my application :

The goal is to update a div with some flash content, systematically,
without needing to write code in every view or method.

I don’t know how to proceed with filters, how to access to the repsonse
body and to change it…

If anybody could help …

thanks

In the application controller, the following code :

after_filter :update_notice

def update_notice
response.body << “”
end

render the expected code on the page :

but this js code is not evaluate…

Stefan B. wrote:

You dont need a filter, you need a layout

http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html

The application is ajax oriented so layouts are not refreshed on every
action, i 'm looking for some generic tool

Stefan B. wrote:

Oh, i see… Sorry

You have to instruct prototype to evalulate the script tags of the xhr
response. afaik, by default, the response is only evaluated if the
mimetype is javascript. but I’m not sure so I suggest you to look it up
in the prototype api and the rails prototype helpers.

Since rails javascript helpers generate
instead of you could try changing that
too.

works when html is rendered but not js. I've to adapt the method depending on the mime type of the response, but i'm in the dark: i can't find any doc on this do you know any paper where the response object is described ? Nico

Oh, i see… Sorry

You have to instruct prototype to evalulate the script tags of the xhr
response. afaik, by default, the response is only evaluated if the
mimetype is javascript. but I’m not sure so I suggest you to look it up
in the prototype api and the rails prototype helpers.

Since rails javascript helpers generate
instead of you could try changing that
too.

nico Itkin wrote:

Stefan B. wrote:

Oh, i see… Sorry

You have to instruct prototype to evalulate the script tags of the xhr
response. afaik, by default, the response is only evaluated if the
mimetype is javascript. but I’m not sure so I suggest you to look it up
in the prototype api and the rails prototype helpers.

Since rails javascript helpers generate ” unless response.headers[‘Content-Type’]
== ‘text/javascript’
end

thank you stefan !

seems i was wrong. nice :slight_smile:

so you’re rendering an rjs template as response and want to add
additional js code using a filter? Phew I don’t think that is possible
without any code in the rjs.