Javascript 在创建rails 3的视图中显示模型基础错误

Javascript 在创建rails 3的视图中显示模型基础错误,javascript,ruby-on-rails,ruby-on-rails-3.1,Javascript,Ruby On Rails,Ruby On Rails 3.1,我有一个表单,用户可以订阅最新的优惠券。当我在多个选项卡中打开同一个商店链接并订阅时,我获得了单个存储的多个订阅,导致数据重复并多次发送相同的邮件。因此,在模型上添加了验证。因此,问题是,当用户已订阅存储时,如何在视图中显示错误。由于create正在发出ajax请求。我已粘贴了下面的代码。如有任何帮助,将不胜感激谢谢 _index.html.haml(视图) 订阅控制器 def create

我有一个表单,用户可以订阅最新的优惠券。当我在多个选项卡中打开同一个商店链接并订阅时,我获得了单个存储的多个订阅,导致数据重复并多次发送相同的邮件。因此,在模型上添加了验证。因此,问题是,当用户已订阅存储时,如何在视图中显示错误。由于create正在发出ajax请求。我已粘贴了下面的代码。如有任何帮助,将不胜感激谢谢

_index.html.haml(视图)

订阅控制器

def create                                                            #creates subscription 
return if !logged_in?
return if current_user.subscription_limit?
@merchant=Merchant.find_by_permalink(params[:merchant_id])
@coupon_subcription=CouponSubscription.new(:merchant_id => @merchant.id,:user => current_user)
@coupon_subcription.coupon_subscribe
respond_to do |format|
  if @coupon_subcription.save!
    format.html { redirect_to(:back, :notice => 'Success.') }  
    format.js
  else
    format.html { redirect_to(:back, :notice => @coupon_subcription.errors.full_messages || "Oops something went wrong")}  
    format.js 

  end
end
UserMailer.delay.coupon_subscription(current_user,@coupon_subcription)
结束

模型

结束

create.js

<% if !logged_in? %>
$(".store_subscribe").remove()
$(".subscription_feedback").show().append("Login!")
<% else %>
$(".store_subscribe").remove()
$(".store_subscribe").show().append("<h3>Thanks for subscription .We have send you a   mail </h3>")
<% end %>

$(“.store_subscribe”).remove()
$(“.subscription\u feedback”).show().append(“Login!”)
$(“.store_subscribe”).remove()
$(“.store\u subscribe”).show().append(“感谢订阅。我们已向您发送邮件”)

在create.js.erb文件中

<% if @coupon_subscription.errors.present? %>
  $("#id").html(@coupon_subscription.errors.full_messages);
<% end %> 

$(“#id”).html(@coupon_subscription.errors.full_messages);
<% if !logged_in? %>
$(".store_subscribe").remove()
$(".subscription_feedback").show().append("Login!")
<% else %>
$(".store_subscribe").remove()
$(".store_subscribe").show().append("<h3>Thanks for subscription .We have send you a   mail </h3>")
<% end %>
<% if @coupon_subscription.errors.present? %>
  $("#id").html(@coupon_subscription.errors.full_messages);
<% end %>