ruby - Rails redirect to the post after a comment is made -


i have comment form on tickets show page. can fill out, when submitting comment, goes comments show page. need go ticket showing.

i have code @ moment:

comment_controller.rb

def create   @comment = comment.new(comment_params)    respond_to |format|     if @comment.save       format.html { redirect_to @comment, notice: 'comment 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 

and similar thing destroy method

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

i'm not sure how remember ticket on, redirect to.

i have entered associations models ticket.rb , comments.rb

you can replace

redirect_to comments_path 

with

redirect_to :back # or  redirect_to(:back) 

which after comment made, returns previous page

if you're using rails 5, use

redirect_back(fallback_location: root_path) 

instead


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -