2016-09-13 65 views
0

私のチケットの表示ページにコメントフォームがあります。私はそれを記入することができますが、コメントを提出するとき、それはコメントのページに行きます。私はこれが表示されていたチケットに戻るために必要です。コメントが投稿された後、投稿にリダイレクトされます

私は現時点ではこのコードを持っている:私はそれを取得するかどうかはわかりません破壊する方法

def destroy 
    @comment.destroy 
    respond_to do |format| 
    format.html { redirect_to comments_path, notice: 'Comment was successfully destroyed.' } 
    format.json { head :no_content } 
    end 
end 

comment_controller.rb

def create 
    @comment = Comment.new(comment_params) 

    respond_to do |format| 
    if @comment.save 
     format.html { redirect_to @comment, notice: 'Comment was successfully created.' } 
     format.json { render :show, status: :created, location: @comment } 
    else 
     format.html { render :new } 
     format.json { render json: @comment.errors, status: :unprocessable_entity } 
    end 
    end 
end 

と同じようなことをそれがリダイレクトされたチケットを覚えておいてください。

私はあなただけのコメントがなされた後

redirect_to comments_path 

を置き換えることができticket.rbとcomments.rb

答えて

2

とモデルとの関連付けを入力しました前のページに戻る

レール5を使用している場合は

redirect_back(fallback_location: root_path) 

代わり

+0

パーフェクトメイトには、それを得ました。 – jimps

関連する問題