我目前只学会了两种最简单的。
1.flash.
The flash provides a way to pass temporary objects between actions. Anything you place in the flash will be exposed to the very next action and then cleared out. This is a great way of doing notices and alerts, such as a create action that sets flash[:notice] = "Post successfully created"
before redirecting to a display action that can then expose the flash to its template. Actually, that exposure is automatically done.
这段话是讲flash可以将临时信息保存一段时间,在不同的动作之间传递,可以用来提示信息。
class PostsController < ActionController::Base def create # save post flash[:notice] = "Post successfully created" redirect_to @post end def show # doesn't need to assign the flash notice to the template, that's done automatically end end show.html.erb <% if flash[:notice] %> <div class="notice"><%= flash[:notice] %></div> <% end %>
这是API中的实例,很简单,不赘述了。
2.直接用javascript中的alert,说来惭愧。