我的 Rails 3 应用程序中的引导模式有问题。它目前可以处理提交和更新数据库的评论表单,但提交表单时模式不会关闭。我尝试将此添加到表单提交按钮:
:data => {:dismiss => "modal"}
但它在不执行更新操作的情况下关闭了模式。这是我的模态代码:
<!-- Review Modal -->
<% if current_user == nil %>
<% else %>
<div id="reviewModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="reviewModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="reviewModalLabel">Write a review</h3>
</div>
<div class="modal-body">
<%= form_for(review_ballot, :remote => true, :html => {:class => 'review_ballot'}) do |f| %>
<h4>Your score:</h4>
<%= f.label("score_1", content_tag(:span, '1'), {:class=>"review", :id=>"1"}) %>
<%= radio_button_tag("review[score]", 1, current_user_review == 1, :class => 'review_button')%>
<%= f.label("score_2", content_tag(:span, '2'), {:class=>"review", :id=>"2"}) %>
<%= radio_button_tag("review[score]", 2, current_user_review == 2, :class => 'review_button')%>
<%= f.label("score_3", content_tag(:span, '3'), {:class=>"review", :id=>"3"}) %>
<%= radio_button_tag("review[score]", 3, current_user_review == 3, :class => 'review_button')%>
<%= f.label("score_4", content_tag(:span, '4'), {:class=>"review", :id=>"4"}) %>
<%= radio_button_tag("review[score]", 4, current_user_review == 4, :class => 'review_button')%>
<%= f.label("score_5", content_tag(:span, '5'), {:class=>"review", :id=>"5"}) %>
<%= radio_button_tag("review[score]", 5, current_user_review == 5, :class => 'review_button')%>
<br />
<h4>What'd you think?</h4>
<%= f.text_area :review_text, :rows => 3, :cols => 10 %>
<%= hidden_field_tag :venue_id, @venue.id %>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<%= submit_tag "Save review", :class => "btn btn-warning" %>
<% end %>
</div>
</div>
这是 review_ballot 方法的场地助手
module VenuesHelper
def review_ballot
if @review = current_user.reviews.find_by_venue_id(params[:id])
@review
else
current_user.reviews.new
end
end
def current_user_review
if @review = current_user.reviews.find_by_venue_id(params[:id])
@review.score
else
"N/A"
end
end
end
我现在不知道该尝试什么。我用谷歌搜索过,没有任何运气。我该如何解决?
编辑:我的临时解决方案 - 我已经:remote => true
从模式中删除并在控制器操作中重定向了访问者,所以现在我不必担心它被解雇。
它显然很笨重/笨拙,所以如果有人可以帮助我解决这个问题,我仍然会喜欢它。愿意根据需要提供更多代码/信息。