2012-02-08 20 views
0

我正在使用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

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 

的問題是,我想要的閃[:成功]出現在當前視圖(..questions/index.html.erb)。消息在視圖/點上閃爍,這不是當前視圖。 flash[:success]應該出現在查看/問題/ index.html.erb。 有什麼我做錯了或不包括?

+0

您沒有使用表單生成器的任何特定原因? http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for – 2012-02-08 05:36:43

+0

@Jeff - 一週前開始真正學習rails,所以我還是習慣了表單建設者。 – squeezemylime 2012-02-08 05:41:52

+0

啊,呃。閃光燈,現在爲你做? 此外,Rails指南是偉大的:http://guides.rubyonrails.org/form_helpers.html#binding-a-form-to-an-object – 2012-02-08 05:48:04

回答

相關問題