2017-02-01 12 views
1

私はポップアップウィンドウにフォームを持っているレールアプリを持っています。私は、ユーザーがサブミットした後にウィンドウを閉じたいと思う。私application.jsでレンダリングレイアウトを使用するとポップアップを閉じることができません

、私は

function windowClose() { 
    "setTimeout(windowClose(), 15000);"; 
} 

は私のフォームは私のルートは私のコントローラは

def bedsheet_line_comments 

    @bedsheet_line = BedsheetLine.find(3081) 

    render :layout => 'alternate' 

    if params[:comments].present? 
     @bedsheet_line = @bedsheet_line.update_attributes(:comments => params[:comments]) 
    end 

    # redirect_to bedsheet_line_path(@bedsheet_line.id) 

    end 
です

get '/bedsheet_liner/comments' =>'bedsheet_lines#bedsheet_line_comments', as: 'bedsheet_line_comments' 
    post '/bedsheet_liner/comments' => 'bedsheet_lines#bedsheet_line_comments' 

ある

<%= form_tag(controller: 'bedsheet_lines', action: 'bedsheet_line_comments', method: "get", id: '3081') do %> 

    <%=text_area_tag e_comment, @current_bedsheet_line.comments %></td> 

    <%= submit_tag "submit", :onclick => "setTimeout(windowClose(), 5000);"%> 

<% end %> 

されてい

render :layout => 'alternate'に電話する必要があります。ポップアップにはapplication.html.erbが提供するヘッダー、フッター、またはナビゲーションがありません。

私がコメントアウトされredirect_to bedsheet_line_path(@bedsheet_line.id)を呼び出そうとした場合、私は

AbstractController::DoubleRenderError in BedsheetLinesController#bedsheet_line_comments 
Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return". 

を取得し提出した後、私は、ウィンドウを閉じるには、Javascriptを(<%= submit_tag "submit", :onclick => "setTimeout(windowClose(), 5000);"%>)を使用して、この周囲で作業しようとしたが、それはウィンドウを閉じている間、それは書き込まれることからの更新を妨げる。遅れは、Railsがウィンドウを閉じる前にデータの書き込みを終了させようとする試みでした。

要約 - 代替レイアウトをレンダリングし、ユーザーが送信ボタンを押した後にユーザーをリダイレクトできるようにしたい。

答えて

1

まず、取得アクションと送信アクションを分けてください。

def show_bedsheet_line_comments 
    @bedsheet_line = BedsheetLine.find(3081) # I don't know if this is used in your view 
    render :layout => 'alternate' 
end 

とあなたのポストの要求がbedsheet_line_comments作用によって提供されています:

def bedsheet_line_comments 
    @bedsheet_line = BedsheetLine.find(3081) 
    if params[:comments].present? 
    @bedsheet_line = @bedsheet_line.update_attributes(:comments => params[:comments]) 
    end 
    render js: "setTimeout(windowClose(), 5000);" 
end 

私たちはget要求がshow_bedsheet_line_comments作用によって提供されるとしましょう

関連する問題