I am not able to signup my user that is getting error while running post method for /signup route.
Please help !!!
This is my routes.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
This is users 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
This is my html gile under users folder under views
<div >
<div >
<div >
Create A New Account
</div>
<div >
<%= 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 >
<%= form_for(:user, url: signup_path) do |f| %>
<% login_path %>
<div >
<div >
<%= 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 >
<div >
<%= f.email_field :email, value: '[email protected]', 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 >
<div >
<%= 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 >
<div >
<%= 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 >
<%= 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>
while submitting the form :
Getting error :
Started POST "/signup" for ::1 at 2022-01-11 00:14:04 0530
ActionController::RoutingError (uninitialized constant UserController
Did you mean? UsersController):
CodePudding user response:
Change the following line in your routes.rb from
post 'signup' => 'user#create'
to
post 'signup' => 'users#create'
because your controller is named UsersController (note the plural).
