Why won't ternary operator work with redirect

前端 未结 2 585
时光取名叫无心
时光取名叫无心 2021-01-23 16:09

I love the ternary operator. It really cleans up the code look, but I have a case where it won\'t behave correctly in a Rails controller.

I get a syntax error: une

2条回答
  •  暖寄归人
    2021-01-23 16:43

    You need to use parentheses in your call to redirect_to so the parser can correctly understand what’s going on:

    nexti==0 ? redirect_to(:back) : redirect_to(edit_playt_path(id: actform['playt_id'], i: nexti))
    

提交回复
热议问题