[英]Unfamiliar error: ActionController::RoutingError at /show uninitialized constant UserController?
[英]Started POST "/signup" for ::1 at ActionController::RoutingError (uninitialized constant UserController Did you mean? UsersController):
在為 /signup 路由運行 post 方法時,我無法注冊出現錯誤的用戶。
請幫忙 !!!
這是我的路線.rb
Rails.application.routes.draw do
get 'signup' => 'users#signup'
post 'signup' => 'user#create'
root 'home#index'
get 'edit' => 'home#edit'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
resources :profiles , only: [:update]
resources :educations , only: [:new]
end
這是用戶 controller
class UsersController < ApplicationController
def signup
end
def create
user = User.find_by(email: params[:user][:email].downcase)
if user && user.authenticate(params[:user][:password])
log_in(user)
redirect_to(root_path)
else
flash.now[:danger] = 'Invalid email/password combination'
render('new')
end
end
end
這是我在視圖下的用戶文件夾下的 html gile
<div class="w-screen h-screen flex justify-center items-center">
<div class="flex flex-col w-full max-w-md px-4 py-8 bg-white rounded-lg shadow dark:bg-gray-800 sm:px-6 md:px-8 lg:px-10 m-10">
<div class="self-center mb-6 text-xl font-light text-gray-600 sm:text-2xl dark:text-white">
Create A New Account
</div>
<div class="flex items-center justify-center mt-6">
<%= link_to "Already have an account? Log in", "/login", class: 'inline-flex items-center text-md font-thin text-center text-gray-500 hover:text-gray-700 dark:text-gray-100 dark:hover:text-white' %></p>
</div>
<div class="mt-8">
<%= form_for(:user, url: signup_path) do |f| %>
<% login_path %>
<div class="flex flex-col mb-2">
<div class="flex relative ">
<%= f.text_field :name, value: 'Aditya', class: 'rounded-lg border-transparent flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-gray-700 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-purple-600 focus:border-transparent', placeholder: 'Your name' %>
</div>
</div>
<div class="flex flex-col mb-2">
<div class="flex relative ">
<%= f.email_field :email, value: 'johndoe@example.com', class: 'rounded-lg border-transparent flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-gray-700 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-purple-600 focus:border-transparent', placeholder: 'Your email' %>
</div>
</div>
<div class="flex flex-col mb-2">
<div class="flex relative ">
<%= f.password_field :password, value: 'password', class: 'rounded-lg border-transparent flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-gray-700 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-purple-600 focus:border-transparent', placeholder: 'New Password' %>
</div>
</div>
<div class="flex flex-col mb-2">
<div class="flex relative ">
<%= f.password_field :cpassword, value: 'password', class: 'rounded-lg border-transparent flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-gray-700 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-purple-600 focus:border-transparent', placeholder: 'Confirm Password' %>
</div>
</div>
<div class="flex w-full">
<%= f.submit "Sign Up", class: "py-2 px-4 bg-purple-600 hover:bg-purple-700 focus:ring-purple-500 focus:ring-offset-purple-200 text-white w-full transition ease-in duration-200 text-center text-base font-semibold shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 rounded-lg" %>
</div>
<% end %>
</div>
</div>
</div>
提交表格時:
得到錯誤:
在 2022-01-11 00:14:04 +0530 開始 POST "/signup" for::1
ActionController::RoutingError (uninitialized constant UserController
Did you mean? UsersController):
將您的routes.rb
中的以下行從
post 'signup' => 'user#create'
至
post 'signup' => 'users#create'
因為您的 controller 被命名為UsersController
(注意復數)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.