Reputation: 709
I am a beginner in ruby on rails. So the scenario is that I am in an index page and I am performing an update in a form displayed on that page. Once the update is done I wish to redirect it back to the index page and reflect the update. i tried this,
def update
format.html { redirect_to action: "index"}
end
This does not seem to work. Any place I am going wrong?
Upvotes: 0
Views: 33
Reputation: 3243
It does not work, becuase format
is not defined. Either use
def update
# some logic...
respond_to do |format|
format.html { redirect_to action: "index"}
end
end
or drop respond_to
and leave just:
def update
# some logic...
redirect_to action: "index"
end
respond_to
is a method that lets you define how your controller action will respond to given format, e.g:
def update
# some logic...
respond_to do |format|
format.html { redirect_to action: "index"}
format.json { render json: {bleh: :blah} }
end
end
Upvotes: 2