views:

78

answers:

1

Hello,

I have a silly question. I'm stuck on that and i don't know how to solve it :)

I have some basic actions like create and destroy comments. I have added the remote => true attribute.

My actions are rendered with a create.js.haml and a destroy.js.haml.

$(".comments").prepend("#{escape_javascript(render(@comment))}");
$("#comments_box .form #new_comment").get(0).reset();

In my controller i have a

flash[:notice] = 'Comment created'

And I would like to update the flash message into the layout.... Into my layout i have this :

 - flash.each do |name, msg|
        = content_tag :div, msg, :id => "flash_#{name}"

What would be the nicer way to create or update the flash message from jQuery (View) ?

Thanks :)

+1  A: 

I solved my problem like that :

In my Layout i added :

#flash_messages
  = render :partial => 'layouts/flash', :locals => { :flash => flash }

The flash partial contains :

- flash.each do |name, msg|
  = content_tag :div, msg, :id => "flash_#{name}"
- if defined?(flush_flash) and flush_flash == true
  - flash.clear

And in my js.haml

$("#flash_messages").html("#{escape_javascript(render(:partial => 'layouts/flash', :locals => {:flash => flash, :flush_flash => true}))}");

Thanks ;)

Arkan