Ajax를 사용하여 빌딩중인 애플리케이션의 다른 컨트롤러에 데이터를 게시하고 있습니다. 사용자는 질문에 대답하기위한 점수를 올바르게 얻습니다.다른 컨트롤러에서 시작 페이지로의 Ajax 콜백
내 원래의보기는 다음과 같습니다 응용 프로그램/의견/질문/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>
내가 게시의 데이터를 저장할 수 있어요 : 응용 프로그램/컨트롤러/points_controller.rb을 :
[: 성공] 현재보기에 표시하기 ( ..questions/index.html.erb)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]
은 view/questions/index.html.erb에 표시되어야합니다. 내가 잘못하고 있거나 포함하지 않는 무언가가 있습니까?
양식 작성기를 사용하지 않는 특별한 이유가 있습니까? http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for –
@Jeff - 일주일 전부터 학습을 시작 했으므로 아직 양식에 익숙해 져 있습니다. 빌더. – squeezemylime
아, 잡았다. 너 플래시 했니? 또한 Rails 가이드는 훌륭합니다. http://guides.rubyonrails.org/form_helpers.html#binding-a-form-to-an-object –