这可能是一个重复的问题,但是以前的答案对我没有帮助
注册页面时,我收到“姓名不能为空”,“手机不能为空”的错误,即使我填写了姓名和手机号也没有
我的routes.rb是
Rails.application.routes.draw do
devise_for :users
namespace :api do
resources :users, :defaults => { :format => 'json' }
end
我的控制器页面
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?
[email protected]?
@user.save
else
render :action => "new"
end
end
def update
super
end
end
我的查看页面是
<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" %>
我的模特是
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
我想念的是什么,...在此先感谢。
最佳答案
问题是我的routes.rb
替换了路线,从
devise_for :users
至,
devise_for :users, :controllers => {:registrations => "registrations"}
现在,它工作正常,...
谢谢你们的回应