0
在我的TestimoniesController
中我寫了一條render js:
行,如果@testimony.save
不成功。Rails 4渲染js:重定向到另一個頁面並顯示原始js
if @testimony.save
redirect_to @testimony
else
render js: "alert('Please make sure you feel out every field of the Testimonial!');"
end
不用翻譯,我寫了警報,它重定向我到/testimonies
路線,只是顯示應該被渲染JavaScript和沒有其他的字符串。我的JS被禁用了嗎?
這裏是我的new.html.erb
文件:
<h1> New Testimonial</h1>
<%= form_for :testimony, url:testimonies_path do |f| %>
<p>
<%= f.label :first_name %><br>
<%= f.text_field :first_name %>
</p>
<p>
<%= f.label :last_name %><br>
<%= f.text_field :last_name %>
</p>
<p>
<%= f.label :email %><br>
<%= f.text_field :email %>
</p>
<p>
<%= f.label :contact_number %><br>
<%= f.text_field :contact_number %>
</p>
<p>
<%= f.label :country %><br>
<%= f.text_field :country %>
</p>
<p>
<!--bunch of the same stuff -->
<p>
<%= f.submit %>
</p>
<% end %>
你加'遙控:TRUE'在你的鏈接,點擊該控制器動作 – Abk
分享您的HTML文件以及 – Abk
我認爲你應該使用的方法和表演js.erb文件對用戶的迴應。 –