Was working on my app and install and uninstall a couple gems and then suddenly the devise stuff stopped working and I can't figure out why. I keep getting the following error:
NoMethodError in Recipes#index
undefined method `registration_path' for #<#<Class:0x00560876ed7ef0>:0x00560876f06430>
Its referring to my sign-up for and this block of code
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), validate: true) do |f| %>
<%= devise_error_messages! %>
<%= f.input :email, validate: true, required: true, placeholder: "Email", label: false %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %>
<%= f.input :password, autocomplete: "off", required: true, placeholder: "Password", label: false %>
<%= f.input :password_confirmation, autocomplete: "off", required: true, placeholder: "Confirm Password", label: false %>
<%= f.input :firstname, required: true, placeholder: "First Name", label: false %>
<%= f.input :lastname, required: true, placeholder: "Last Name", label: false %>
<%= f.input :displayname, validate: true, placeholder: "Display Name", label: false %>
<div class="recaptcha">
<%= recaptcha_tags %>
</div>
<%= f.button :submit, "Sign up", class: 'btn btn-primary' %>
<% end %>
In my routes.rb i have this:
Rails.application.routes.draw do
devise_for :users, controllers: { registrations: 'registrations', omniauth_callbacks: "callbacks" }
And this is the registrations controller:
class RegistrationsController < Devise::RegistrationsController
def sign_up_params
params.require(:user).permit(:firstname, :lastname, :displayname,
:email, :password, :password_confirmation)
end
def account_update_params
params.require(:user).permit(:firstname, :lastname, :displayname,
:email, :password, :password_confirmation)
end
def create
if !verify_recaptcha
flash.delete :recaptcha_error
build_resource(sign_up_params)
resource.valid?
resource.errors.add(:base, "There was an error with the recaptcha code below. Please re-enter the code.")
clean_up_passwords(resource)
respond_with_navigational(resource) {render :new}
else
flash.delete :recaptcha_error
super
end
end
def after_inactive_sign_up_path_for(resource)
'/pages/confirm_email'
end
end
I have the devise stuff in the user model and controller that is standard and nothing changed with them but it stopped working. Not sure how to fix this
Edit: The rake route shows the registration path isnt in there for some reason:
Prefix Verb URI Pattern Controller#Action
rails_admin /admin RailsAdmin::Engine
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_google_oauth2_omniauth_authorize GET|POST /users/auth/google_oauth2(.:format) callbacks#passthru
user_google_oauth2_omniauth_callback GET|POST /users/auth/google_oauth2/callback(.:format) callbacks#google_oauth2
user_facebook_omniauth_authorize GET|POST /users/auth/facebook(.:format) callbacks#passthru
user_facebook_omniauth_callback GET|POST /users/auth/facebook/callback(.:format) callbacks#facebook
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
user_password PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
POST /users/password(.:format) devise/passwords#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
user_confirmation GET /users/confirmation(.:format) devise/confirmations#show
POST /users/confirmation(.:format) devise/confirmations#create
Ok so this error is baffling me. I am using docker-compose for my development and ive rebuilt the containers and images. Deleted everything and started over. Something in signup settings of devise got messed up and not sure where to look to see if it is correct. So when I go to: localhost:8000/users/sign_in
Everything works fine and it goes to the devise sign-in page...but when I go to localhost:8000/users/sign_up
It says Couldn't find User with 'id'=sign_up
. Its like the devise_for :users is being ignored for the sign-up stuff and not sure where to look for that cause thats all internal to the gem...I think
So after many hours of digging thru my code, comparing to my old code and googling every combination of devise and registration I could think. I stumbled upon the problem and it was stupid...Somewhere in editing my User.rb model I accidently deleted :registable from the devise modules. That is why it wasnt generating the registration routes. So fixed my line of code from this:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, omniauth_providers: [:google_oauth2, :facebook]
to This:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, omniauth_providers: [:google_oauth2, :facebook]
Not sure where or how that got deleted but it did and cause it was in the middle of the block didnt notice as I was looking over my code