开发者

How do you access the rails 2 flash[] hash in jQuery?

Ok, I'm sure there is something simple that I'm missing here, but I can't quite seem to find the answer.

I have a modal that I updates both via norm开发者_如何学JAVAal HTTP request and now I'm adding some unobtrusive AJAX with jQuery to process the same request.

After the controller action I have user messages delivered in the flash[] hash (IE flash[:errors], flash[:message]) This is then displayed in on the redirect to page.

My question is: How do I access this flash hash in my respond to .js file? What I want to do is something like:

$("#message").append(ADD FLASH MESSAGE HERE || render a message partial)


Your jquery code can be treated just like any other (html) part of the partial template. So for your example, you should be able to use:

$("#message").append('<%= flash[:error] || render(:partial => :my_msg_partial) %>')


You could try something like flash.to_json

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜