通过json将闪存通知或警报传递给客户端

时间:2014-12-23 09:10:24

标签: javascript ruby-on-rails json angularjs

我是Rails和angularJs的新手,我需要将带有json数据的通知消息传递给我的视图 这是我的方法创建

def create
 @cart= Panier.create(book_id: params[:book_id], title: params[:title], price: params[:price], quantity: params[:quantity],user_id: params[:user_id])
 respond_to do |format|
  if @cart.save()

    format.json { render json: @cart, status: :created, location: @cart ,message: "added successfully to your cart" }
  else

    format.json {render json: @cart.errors, status: :unprocessable_entity, message: "can't be a dadded to your cart"}
  end
 end
end

那么如何在我的网页上显示这些消息呢?

0 个答案:

没有答案