我最近在我的页面中添加了一个管理员用户,现在我的“创建”功能不再有效,但我的“编辑”功能仍然有效。当我尝试创建新项目时,我没有收到任何错误。
application_controller.rb:
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :is_admin, only: [:new, :create, :edit, :update, :delete, :destroy, :admin]
helper_method :admin?
protected
def admin?
session[:password] == 'pass'
end
def authorize
unless admin?
flash[:error] = "unauthorized access"
redirect_to root_path
false
end
end
def is_admin
redirect_to root_path, notice: "You are not authorized for that." unless admin?
end
end
如果我取出 before_filter,它仍然不起作用。
members_controller.rb
def new
@member = Member.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @member }
end
end
def edit
@member = Member.find(params[:id])
end
def create
@member = Member.new(params[:member])
respond_to do |format|
if @member.save
format.html { redirect_to @member, notice: 'Member was successfully created.' }
format.json { render json: @member, status: :created, location: @member }
else
format.html { render action: "new" }
format.json { render json: @member.errors, status: :unprocessable_entity }
end
end
end
def update
@member = Member.find(params[:id])
respond_to do |format|
if @member.update_attributes(params[:member])
format.html { redirect_to @member, notice: 'Member was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @member.errors, status: :unprocessable_entity }
end
end
end
在我的routes.rb 我有resources :members
有什么想法为什么我的创作突然退出了我,但所有其他功能仍在工作?我所有的页面都是这样的,而不仅仅是“会员”