what is the difference between link_to, redirect_to, and render?

后端 未结 9 815
余生分开走
余生分开走 2020-12-09 08:16

I am confused about the main difference(s) among link_to, redirect_to and render in Rails. anyone can please explain.

9条回答
  •  情话喂你
    2020-12-09 08:46

    link_to is for use in ERB templates. It outputs a link to a specific path or url.

    redirect_to is for use in controllers. It causes the client to request the specified path or url once the controller method exits.

    render is also for use in controllers. It causes Rails to render the specified template.

    redirect_to and render may only be called once in a given controller method.

提交回复
热议问题