Ruby's name cannot be an empty mistake

this may be a repeat question, but the previous answers do not help me

I received "name cannot be empty", "mobile error cannot be empty" when registering the page, although I filled in the name and mobile number

my routes.rb

Rails.application.routes.draw do
 devise_for :users
 namespace :api do
  resources :users, :defaults => { :format => 'json' }
 end 

      

my controller page

class RegistrationsController < Devise::RegistrationsController

skip_before_filter :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' }
def new
    @user = User.new
end

def create
    params.permit!
    @user = User.new(params[:user])
    @user = User.new
    @user.name = params[:user][:name]
    @user.email = params[:user][:email]
    @user.mobile_no = params[:user][:mobile_no]
    @user.password = params[:user][:password]
    @user.valid?
    if@user.errors.blank?
        @user.save
    else
        render :action => "new"
    end
end

def update
    super
end
end

      

my view page

 <h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url:   registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>
  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name, autofocus: true %>
  </div>
  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email, autofocus: true %>
  </div>
  <div class="field">
    <%= f.label :mobile_no %><br />
    <%= f.telephone_field :mobile_no, autofocus: true %>
  </div>
  <div class="field">
    <%= f.label :password %>
    <% if @validatable %>
    <em>(<%= @minimum_password_length %> characters minimum)</em>
    <% end %><br />
    <%= f.password_field :password, autocomplete: "off" %>
  </div>


  <div class="actions">
        <%= f.submit "Sign up" %>
      </div>
    <% end %>

    <%= render "devise/shared/links" %>

      

my model

class User < ActiveRecord::Base
    devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
    def users_params
    params.require(:users).permit(:name, :email, :mobile_no, :password)
    end
    validates :email,:name, :mobile_no :presence =>true
    validates_uniqueness_of :email
 end

      

what i am missing, ... thanks in advance ....

+3


source to share


1 answer


the problem is with my routes. rb

changed the route from

devise_for :users

      

in



devise_for :users, :controllers => {:registrations => "registrations"}

      

now it works fine, ...

thanks guys for the answer

+1


source







All Articles