我正在尝试使用Devise Gem。我尝试在没有登录的情况下创建帐户。模型控制器返回此错误: Error
我不明白。导致此错误的原因是什么?我在github上的项目是https://github.com/linneudm/tesouraria-dm
members_controller:
class MembersController < InheritedResources::Base
before_action :set_member, only: [:show, :edit, :update, :destroy]
before_action :authenticate_member!
# GET /members
# GET /members.json
def index
@members = Member.all
end
# GET /members/1
# GET /members/1.json
def show
end
# GET /members/new
def new
new!
end
# GET /members/1/edit
def edit
end
# POST /members
# POST /members.json
def create
create!
respond_with(@member, :location => nil)
end
# PATCH/PUT /members/1
# PATCH/PUT /members/1.json
def update
respond_to do |format|
if @member.update(member_params)
format.html { redirect_to @member, notice: 'Member was successfully updated.' }
format.json { render :show, status: :ok, location: @member }
else
format.html { render :edit }
format.json { render json: @member.errors, status: :unprocessable_entity }
end
end
end
# DELETE /members/1
# DELETE /members/1.json
def destroy
destroy! { members_url }
end
private
# Use callbacks to share common setup or constraints between actions.
def set_member
@member = Member.find(params[:id])
end
private
def permitted_params
params.permit(:member => [:name, :email, :password, :password_confirmation,:dt_Admission, :situation, :function, :start_Managment])
end
# Never trust parameters from the scary internet, only allow the white list through.
def member_params
params.require(:member).permit(:name, :email, :password, :password_confirmation, :dt_Admission, :situation, :function, :start_Managment)
end
end
registrations_controller:
class RegistrationsController < Devise::RegistrationsController
before_action :update_sanitized_params, if: :devise_controller?
def update_sanitized_params
devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:name, :email, :password, :password_confirmation)}
devise_parameter_sanitizer.for(:account_update) {|u| u.permit(:name, :email, :password, :password_confirmation, :current_password)}
end
end
路线:
Rails.application.routes.draw do
as :member do
resource :registration, only: [:edit, :update], :path => '/members'
end
resources :members, :only => [:new, :create]
devise_for :members, :controllers => { :registrations => 'registrations'}
resources :expenses
resources :incomings
resources :expenses
resources :members
get 'home/index'
root to:'home#index'
#post 'members' => 'members#create ', as: :create_member
end
_form.html.erb - 注册
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), :html => { :class => "form-horizontal member" }) do |f| %>
<%= devise_error_messages!%>
<div class="form-group">
<%= f.label :name, :class => 'control-label col-lg-2' %>
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<%= f.text_field :name, autofocus: true, :class => 'form-control' %>
</div>
</div>
<%=f.error_span(:name) %>
</div>
<div class="form-group">
<%= f.label :email, :class => 'control-label col-lg-2' %>
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
<%= f.email_field :email, :class => 'form-control' %>
</div>
</div>
<%=f.error_span(:email) %>
</div>
<div class="form-group">
<%= f.label :password, :class => 'control-label col-lg-2' %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %>
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<%= f.password_field :password, autocomplete: "off", :class => 'form-control'%>
</div>
</div>
<%=f.error_span(:password) %>
</div>
<div class="form-group">
<%= f.label :password_confirmation, :class => 'control-label col-lg-2' %>
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<%= f.password_field :password_confirmation, autocomplete: "off", :class => 'form-control' %>
</div>
</div>
<%=f.error_span(:password_confirmation) %>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<%= f.submit "Sign up", :class => 'btn btn-primary' %>
<%= link_to "Log in", new_member_session_path, :class => 'btn btn-info' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
root_path, :class => 'btn btn-default' %>
</div>
</div>
<% end %>
答案 0 :(得分:0)
网址为member.members
,rails将'.members'
作为扩展名,例如.json或.xml,这就是您收到此错误的原因。
答案 1 :(得分:0)
此错误显示是因为您没有请求将网址作为json或html.check您的控制台知道它以哪种格式命中网址。