当我在我的rails项目上处理用户表单中的验证错误时,如果用户无效,我有指令render 'new'
。呈现'新'导致不同的网址
但是,当发生这种情况时,搜索栏中的网址会发生变化。
原来,这是https://localhost:3000/signup
但是当用户提交表单和render 'new'
发生时,URL成为https://localhost:3000/users
这是为什么?
这里是我的routes.rb
Rails.application.routes.draw do
# Resources
resources :users, only: [ :new, :create ]
# Application root
root 'static_pages#home'
# Static pages
get '/help', to: 'static_pages#help'
get '/contact', to: 'static_pages#contact'
# Users
get '/signup', to: 'users#new'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
感谢,
虽然这确实解决了直接的问题,但它带来了一些历史相关的问题,而轨道约定旨在避免这些问题。在破解规则之前了解规则。 – max