【发布时间】:2012-02-08 04:40:00
【问题描述】:
我正在使用 Ajax 将数据发布到我正在构建的应用程序的不同控制器。用户正确回答问题获得积分。
我的原始视图是:app/views/questions/index.html.erb
<form accept-charset="UTF-8" action="/points/create" method="post" data-remote="true" id="formname">
<div class="field">
<%= radio_button("point", :user_answer, 1) %>
<%= label_tag(:correct_answer, question.answer1 ) %>
<%= radio_button("point", :user_answer, 2) %>
<%= label_tag(:correct_answer, question.answer2) %>
<%= radio_button("point", :user_answer, 3) %>
<%= label_tag(:correct_answer, question.answer3) %>
<%= radio_button("point", :user_answer, 4) %>
<%= label_tag(:correct_answer, question.answer4) %>
</div>
<div class="actions">
<input type="hidden" id="point_question_correct_answer" name="point[correct_answer]" value="<%= question.correct_answer %>" />
<input type="hidden" id="point_question_id" name="point[question_id]" value="<%= question.id %>" />
<input type="hidden" id="point_current_user" name="point[user_id]" value="<%= current_user.id %>" />
<%= submit_tag "Submit", :class => 'btn btn-primary' %>
</div>
我可以在以下位置发布和保存数据:app/controllers/points_controller.rb:
def create
@point = Point.new(params[:point])
respond_to do |format|
if @point.save
logger.debug "Data has been saved"
flash[:success] = "Data has been saved"
else
end
end
end
问题是我希望 flash[:success] 出现在当前视图中(..questions/index.html.erb)。消息在视图/点上闪烁,这不是当前视图。 flash[:success] 应该出现在 view/questions/index.html.erb 上。
我做错了什么或不包括什么?
【问题讨论】:
-
您不使用表单生成器的任何特殊原因? api.rubyonrails.org/classes/ActionView/Helpers/…
-
@Jeff - 大约一周前开始真正学习 Rails,所以我还在习惯表单构建器。
-
啊,明白了。 flash.now 为你做了吗?此外,Rails 指南也很棒:guides.rubyonrails.org/…
-
当然......其他一切都进行得很顺利,我认为有一些基本的东西我没有得到这个,因为它应该很简单但我正在撞墙..
标签: ruby-on-rails ajax