heroku js.erb文件输出它应该呈现为文本的表单

时间:2017-02-26 10:44:25

标签: heroku ruby-on-rails-5

这是网站:https://deadindustry-newnew-recruit.herokuapp.com/

这里是github:daveasdf / deadindustry_newnew_recruit

当您输入表单时,它应该呈现表单和右侧的支持者列表,而是在https://deadindustry-newnew-recruit.herokuapp.com/supporters.js(这是一个随机网页)上吐出它们的文本版本。

我不是开发者,我只是一名音乐家,所以我很感激所有的帮助。另外,请查看我的乐队:soundcloud.com/whorwood

这里有具体细节:

页:

<div class="row">
  <div class="col-md-12">
    TEXT
  </div>
</div>
<br>


<div class="row"> 
  <div class="col-md-4">
    <div id="home_form">
      <%= render "supporters/form" %>
    </div>
  </div>
  <div class="col-md-2">
  </div>
  <div class="col-md-6" id="home_list">
    <br>
    <%= render 'supporters/show_supporters' %>
  </div>
</div>

控制器:

class SupportersController < ApplicationController

  ...  
  def create
    @supporter = Supporter.new(supporter_params)
    @supporters = Supporter.all.order(created_at: :desc)

    respond_to do |format|
      format.js
    end
  end

  ...

create.js

<% if @supporter.save %>
    $("#home_list").html("<%= j render 'show_supporters' %>")
    $("home_form").html("<%= j render 'form' %>")
<% else %>
    $("#home_form").html("<%= j render 'form', supporter: @supporter %>") 
    $('#build_error').remove();
    <% if @supporter.errors.any? %>
      var build_error = "<div class='alert alert-danger' id='build_error'>";
      build_error += "You've got <%= pluralize(@supporter.errors.count, 'error') %>.";
      build_error +=   "<ul id='error_explanation'>";
      <% @supporter.errors.full_messages.each do |msg| %>
        <% if msg === "Ip has already been taken" %>
            <% msg = "You've already posted your support.   Thanks!" %>
        <% end %>
        build_error += "<li><%= j msg %></li>";
      <% end %>
      build_error +=   "</ul>";
      build_error += "</div>";
      $(build_error).insertBefore( "#home_form" );
    <% end %>           
<% end %>

1 个答案:

答案 0 :(得分:0)

您将错误的操作传递给表单

<form novalidate="novalidate" class="simple_form new_supporter" id="new_supporter" 
action="/supporters.js" accept-charset="UTF-8" data-remote="true" method="post">

而不是/supporter.js应该只是/supporters

您需要从此行中删除format: :js

<%= simple_form_for(@supporter, remote: true, format: :js) do |f| %>