【发布时间】:2020-09-13 16:44:04
【问题描述】:
我正在尝试渲染 new.js.erb 以防验证失败。 我的rails create action中有这个
def create
@talent = Talent.new(talent_params)
@job = params[:job_id]
@talent.job_id = @job
respond_to do |format|
if @talent.save
flash[:notice] = "You have successfully completed your job application!"
redirect_to jobs_path
else
format.html
format.js { render "new" }
end
end
end
在new.js.erb中,我有
$('<%= j render "form" %>').modal();
在_form.html.erb(new.js.erb中部分渲染的表单),我有
<div id="contact-modal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<%= simple_form_for @talent, :url => job_talents_path(@job, @talent), :method => :post do |f| %>
<div class="modal-body">
<%= f.input :full_name, label: "Full Name", :autofocus => true %>
<%= f.input :email, label: "Email" %>
<%= f.input :mobile_number, label: "Mobile Number" %>
<%= f.input :resume %>
<%= f.input :cover_letter %>
<%= f.submit 'Submit Application', class: "btn btn-success btn-lg btn-block upload-margin create-style"%>
</div>
<div class="modal-footer">
<span style="float: left; color: #5DB1D1;">Goodluck with your application<i class="fas fa-hand-peace" aria-hidden="true"></i></span>
</div>
<% end %>
</div>
</div>
</div>
如果验证失败,控制器将无法呈现 new.js.erb。任何帮助解决这个问题将不胜感激
【问题讨论】:
-
当“控制器无法渲染
new.js.erb”时,会发生什么? -
什么也没发生,但我在堆栈跟踪中看到了这个“没有找到 TalentsController#create 的模板,渲染头:no_content 已完成 204 14 毫秒内没有内容(ActiveRecord:0.7 毫秒 | 分配:8343)”跨度>
-
在 new.js.erb 中,你是在告诉渲染什么,而不是在哪里渲染。
标签: javascript jquery ruby-on-rails ruby modal-dialog