使用 Rails REST 助手,您如何区分创建和索引之间的区别?

With Rails REST helpers, how do you tell the difference between create and index?

我在查找 Rails REST 助手时注意到 createindex 共享一个共同的助手(使用主题作为变量)subjects_path。如果您想在将请求重定向到 indexcreate 的位置使用 link_to,您如何区分?他们是否需要共享相同的 URL 和 URL 助手?

create 使用 POST HTTP 协议方法,而 index 使用 GET.

因此,对于您的 link_to 示例:link_to 'create', subjects_path, method: :post(默认值为 GET