Default .rjs

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!

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.

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.

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. [email protected]

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. [email protected]n.invalid

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

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-

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs