重复的POST方法,为什么?

时间:2014-06-05 13:00:18

标签: javascript jquery ruby-on-rails simple-form

我在提交表单时遇到问题,它正在制作一个重复的帖子方法,我不知道为什么因为我在我的js中阻止了Default。在房间里有任何iluminatti?

我的JS

<% if @photo.user = current_user %>
 <script> $("#tp_tag_save").on('click', function(event) {
  event.preventDefault();
    $.post("/users/<%= current_user.id %>/photos/<%= @photo.id %>/tags", {
      "tag[name]" : $("#tag_name").val(),
      "tag[location]" : $("#tag_location").val(),
      "tag[price]" : $("#tag_price").val(),
      "tag[coordinate_x]" : $("#tag_coordinate_x").val(),
      "tag[coordinate_y]" : $("#tag_coordinate_y").val()
    }).done(function (data) {
      drawTag($("#tag_name").val(), $("#tag_price").val(), $("#tag_location").val(), $("#tag_coordinate_x").val(), $("#tag_coordinate_y").val()),
      reDrawList();
    });
    modal("#tag_modal", "hide", 200);
  });
</script>
<% end %>

我的表格

<div class="large-5 center semi_padding_top columns large-centered ">
    <h1> <i class="icon-photo"></i>Subir un spot</h1>
    <h6 class="lightgrey thin">Los spots son rincones de tu casa, oficina o negocio de los que estés orgulloso de cómo están decorados. </h6>
    <%= simple_form_for [current_user, @photo] , html_input: "data-abide" do |f| %>
        <div class="new_spot_form deco-form semi_padding_top">
            <%= f.input :title , label: "Ponle un título a tu spot", html_input: "required", class: "input" %>
            <%= f.input :description, label: "¿Qué te gusta de este spot?" , class: "textarea" %>
            <%= f.input :photo, label: "Ahora sube tu foto", input_html: { id: 'fileElem'} %>
            <button id="fileSelect" class="semi_margin_bottom" type="button"><i class="valign-m quarter_padding_right icon-magnifier"></i>Seleccionar spot</button>
            <%= f.label "Selecciona el estilo de tu spot" %>
            <%= f.collection_select :category_id, Category.all, :id, :name%>
            <%= f.label "Selecciona la zona de tu spot" %>
            <%= f.collection_select :zone_id, Zone.all, :id, :name %>
            <%= f.input :terms , label: "Tengo los derechos de esta foto" %>
            <%= f.button :submit, "Subir Spot", input_html: {class: 'icon-magnifier button'} %>
        </div>
    <% end %>
</div>

1 个答案:

答案 0 :(得分:2)

你如何调用你的js代码? 我看到其中有一个错误

<% if @photo.user = current_user %>

如果在循环中使用此代码,它将被调用两次。

在那种情况下重写

<% if @photo.user == current_user %>