When to use render vs redirect_to when handling error validations

后端 未结 2 1692
猫巷女王i
猫巷女王i 2021-01-16 06:25

I have a fairly complex view that has multiple forms, lots of validations on those forms, paginations, and other features. When validations fail, I like to use render becau

2条回答
  •  失恋的感觉
    2021-01-16 06:59

    First, these are not compiler error - its run-time errors.
    Second, you should either check your data in the controller to make sure its being served properly for rendering OR do some conditional blocks in the view in order to cope with this different data structures.

    Lastly, redirect_to is just a technique of moving the user around, it could be used here but you still need to handle those errors, even in the redirected-to page...

    HTH

提交回复
热议问题