# Default .rjs

**URL:** <https://www.ruby-forum.com/t/default-rjs/177092>\
**Category:** Rails\
**Created:** [October 11, 2009, 2:25pm UTC](https://www.ruby-forum.com/t/default-rjs/177092 "2009-10-11T14:25:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 11, 2009, 2:25pm UTC](https://www.ruby-forum.com/t/default-rjs/177092/1 "2009-10-11T14:25:48Z")

</div>

Hi,

I’ve asked this before, but I wasn’t sure what I was looking for and  
what the problem was back then.

What I want is to be able to tell Rails that after -every- AJAX-  
request, some default RJS gets executed. I’ve tried using an  
after\_filter rendering an rjs-file, but because all of my methods  
already use RJS, Rails produces an error similar to when you use two  
redirects in one request. I can, of course, add some code to every  
file, but that wouldn’t be very DRY.

How can I tell Rails, just like you do with your application layout  
for example, to do some general stuff in addition to the specific code  
in my .rjs files?

Thank you!

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 12, 2009, 8:12pm UTC](https://www.ruby-forum.com/t/default-rjs/177092/2 "2009-10-12T20:12:37Z")

</div>

Anyone? I plan on implementing error reporting in my app at the end of  
this week and I could really use your thoughts on this.

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 12, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/default-rjs/177092/3 "2009-10-12T21:50:55Z")

</div>

jhaagmans wrote:

> Anyone? I plan on implementing error reporting in my app at the end of  
> this week and I could really use your thoughts on this.

You could… Override the class definitions for those calls and hard-code  
something like:  
:after =\> “run this”  
…

I’m talking from a deep and dark place here, where the sun doesn’t shine  
much, but I can’t really see another solution.

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 13, 2009, 9:21am UTC](https://www.ruby-forum.com/t/default-rjs/177092/4 "2009-10-13T09:21:46Z")

</div>

But it can’t be that I’m the only one who wants to implement such  
functionality! It’s something every Rails programmer using AJAX calls  
will face, isn’t it? How do those people handle centralized error  
messages? Do they just add code to every rjs file?

On 12 okt, 21:50, Aldric G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 13, 2009, 4:12pm UTC](https://www.ruby-forum.com/t/default-rjs/177092/5 "2009-10-13T16:12:12Z")

</div>

jhaagmans wrote:

> But it can’t be that I’m the only one who wants to implement such  
> functionality! It’s something every Rails programmer using AJAX calls  
> will face, isn’t it? How do those people handle centralized error  
> messages? Do they just add code to every rjs file?

If you use validations, won’t Rails just return error messages in the  
HTML anyway?

> On 12 okt, 21:50, Aldric G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 13, 2009, 4:40pm UTC](https://www.ruby-forum.com/t/default-rjs/177092/6 "2009-10-13T16:40:50Z")

</div>

It will return error messages like any other Rails requests, but it  
won’t update your flash, so the only thing that happens is that it  
returns an error. You won’t be able to show it if you can’t update the  
page.

What I’ll do now, for the time being:

def create  
@item = Item.new(params[:item])  
if @item.save  
#render all kinds of things  
else  
@item.report\_errors  
end  
end

private

def report\_errors  
flash[:warning] = this.errors.full\_messages.join("  
")  
render :action =\> “update\_errors.rjs”  
end

But I have a feeling this isn’t as DRY as it can be.

On 13 okt, 16:12, Marnen Laibow-Koser \<rails-mailing-l…@andreas-
