json数据 提示框flash.now[:notice] flash.now[:alert]

实现json、做出提示框

 

1、在controller中使用flash.now[:alert] = "str"方法来做print

def topodata
  #@vnic = Vnic.all
  #flash.now[:notice] = 'Message sent!'
  #flash.now[:alert] = 'Message sent!'
  @vnic = {
    nodes: [{ name: 'bob', age: "22", awesome: "true" }, { name: 'bob', age:      22, awesome:true }],
links: [{ name: 'bob', age: "22", awesome: "true" }, { name: 'bob', age: 22,  awesome:true }]
  }
  flash.now[:alert] = @vnic
  respond_to do |format|
    format.html
    format.json { render json: @vnic } #这里会自动调用to_json
  end
end

  

2、在view中使用链接来做提示 alert也可以换做confirm

<a href= 'http://192.168.1.251:3000/vnets'  onclick="return(alert('<%= current_user.email %>'))">删除</a>

posted @ 2014-09-04 00:25  juandx  阅读(453)  评论(0编辑  收藏  举报