當我在我的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