Is it possible when validation to make redirect to same url (site.com/posts/1/edit), keeping the previously entered data? not to (site.com/posts/)
I mean
site.com/posts/1/edit ---> validate failed ---> site.com/posts/1/edit
Thank you for your help!
You can use the following snippet:
def update
@post= Post.new(params[:post])
if @post.valid?
redirect_to valid_path
else
render action: "edit"
end
end
If the user isn't valid rails will render the edit page again. The form values will be filled again if you used form_for @post
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.