1

flash 方法仅在页面重新加载后显示消息...当我使用 :remote => true 时,我该怎么做才能让它出现?

4

1 回答 1

2

如果你使用 :remote => true 你实际上是在做 Ajax 请求。在这种情况下,闪光灯将无法工作。

您需要的是有一个模仿该 Flash 消息的 js 函数。

我通常有这个:(Mootools,但你可能明白了)

showMessage: function(message, style, addReload)
    {
        var class_name = style + "_message message";

        var flash = $("flash_message");

        if (flash) {
            flash.dispose();
        }

        flashElement = new Element("div", {
            id: 'flash_message'
        });
        flashElement.set('class', class_name);

        var strong = new Element('strong', { 
                                html: message
                                });

        if(addReload)
        {
            strong.adopt(
                            new Element("a", {href: window.location, html: 'Reload'})
                        );
        }

        flashElement.adopt(
                            strong
                        );


        flashElement.inject($("mainPageContainer"));
        Site.show_message();
    },

每当我使用 :remote => true 时,我都会在 js 视图中使用它

<% flash.discard %>
Dashboard.showMessage('Comment added and was sent to clients', 'notice');
于 2012-02-19T08:22:12.220 回答