i'm trying to use devise for handling user login/registration/forgotten password
I want to have sign up form at my root url root 'home#index'
HomeController
class HomeController < ApplicationController
include DeviseHelper
def index
end
end
DeviceHelper
module DeviseHelper
def resource_name
:user
end
def resource_class
User
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
views/home/index.html.erb
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
when I try to sign up with wrong attributes it shows me this error
undefined method `devise_error_messages!' for #<#:0x007fb430638300>
how can I fix this error. Also is using Devise module good practise?
The best option is to rename your own DeviseHelper to something else. Rails's autoloading is finding your implementation of DeviseHelper instead of Devise's, so the method is not being loaded. Call it something less specific, e.g. AuthHelper.
The advantage of this over pulling in your own implementation do devise_error_messages! is that you will automatically pick up changes to the method that Devise may make in future versions, as well as you'll have less code in your app, both making your code more sensible / maintainable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With