私はRuby on Railsを使ってWebアプリケーションを書いています。 new.html.erbでRuby/JS送信ボタンの後にページをリロードする方法は?
def create
@category = Category.new(category_params)
respond_to do |format|
if @category.save
format.html { redirect_to @category, notice: 'Category was successfully created.' }
format.json { render :show, status: :created, location: @category }
format.js { render js: 'window.top.location.href = "/categories";' }
else
format.html { render :new }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
:_form.html.erbで
<h1>New category</h1>
<%= render 'form' %>
<%= link_to 'Back', categories_path %>
:コントローラで
<%= form_for(@category) do |f| %>
<% if @category.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2>
<ul>
<% @category.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :content %><br>
<%= f.text_field :content, placeholder: "content" %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description, placeholder: "description" %>
</div>
<div class="actions">
<a href="#" onclick="window.top.location.reload(true)"><%= f.submit %>
</a>
</div>
<% end %>
は私が機能するためにボタンを提出したいと新しく作成されたカテゴリは、ページがリフレッシュされる前に保存されます。コードでは、保存前にページがリフレッシュされます。 助けてください。おかげ
削除 'onclick =" window.top.location.reload(true) "' – madalinivascu