实现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>

相关文章:

  • 2021-09-20
  • 2021-11-17
  • 2021-06-12
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-30
  • 2021-12-02
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案