Rails アプリに単純な投票アクションがあり、作成アクションが成功した後にモーダル ポップアップ (Twitter ブートストラップの on など) を表示したいと考えています。モーダル ビュー パーシャル、.js を受け入れる Respond_to ブロック、および作成アクションが呼び出されたときに理論上表示される create.js.erb ファイルがあります。
これらすべてを一緒に配線する方法がよくわかりません(また、javascriptが間違っていると思います)どんなヒントでも大歓迎です!
controller.rb
def create
@vote = Vote.new(params[:vote])
respond_to do |format|
if @vote.save
format.html { redirect_to :back, notice: "Thank you for voting! why not Tweet your vote?" }
format.js <!--should there be a call to a specific file here?-->
else
flash[:error] = "please try again"
redirect_to :back
end
end
end
end
投票/info.html.erb
<div class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Thanks for voting!</h3>
</div>
<div class="modal-body">
<p>Why not tweet your selection?</p>
</div>
<div class="modal-footer">
<a href="#" class="btn">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div>
</div>
投票/create.js.erb
$(".modal").html(<%= escape_javascript render partial: 'votes/info' %>);
$(".modal").show();
投票_form.html.erb
<%= form_for([Vote.new(hotel_id: hotel.id)]) do |f| %>
<%= f.hidden_field :hotel_id %>
<%= f.submit "Vote", class: "btn-large btn-info" %>
<% end %>