我正在实施ActiveAdmin以CRUD我的应用程序的内容。到现在为止还挺好。 但是我收到错误:当我在管理员面板中访问“新建”操作时,找不到没有和ID的女孩。
我的ActiveAdmin控制器:
controller do
def create
@advertisement = Girl.new(girl_params)
respond_to do |format|
@advertisement.bypass_humanizer = true
if @advertisement.save
if params[:images]
params[:images].each { |image|
@advertisement.pictures.create(image: image)
}
end
format.html {redirect_to admin_girl_path(@advertisement)}
format.json { render :json => @advertisement, :status => :created, :location => @advertisement }
else
format.html { render :action => "new" }
format.json { render json: @advertisement.errors.full_messages, status: :unprocessable_entity }
end
end
end
def new
@advertisement = Girl.new
end
def edit
@advertisement = Girl.find(params[:id])
end
def update
@advertisement = Girl.find(params[:id])
flash[:notice] = 'Girl was successfully updated.' if @girl.update(girl_params)
redirect_to :back
end
def show
@advertisement = Girl.find(params[:id])
end
def destroy
@advertisement = Girl.find(params[:id])
@advertisement.destroy
redirect_to :back
end
def girl_params
# NOTE: Using `strong_parameters` gem
params.required(:girl).permit(:id,:humanizer_question_id, :_destroy, :confirmed_at,:bypass_humanizer,:humanizer_answer, :identifier, :token,:name, :work1,:subname,:paid, :work2, :check, :can_add_review,:work3, :work4,:smsidentifier,:smsidentifier_confirmation,:provaider, :expiration,:your_ip,:in_blacklist,:admin_confirmed,:country_id, :region_id,:user_id,:phone_number,:image,:terms_of_service,:region,:age,:height,:weight,:description,:description_ru,:email, hour_ids: [], pictures_attributes: [:image], service_ids: [])
end
end
我不知道从哪开始。我看不出问题。
我尝试了什么:
将girl_params
更改为permit_params :id,:humanizer_question_id,...
然后
def create
@advertisement = Girl.new(permited_params[:girl])
end
但这并没有解决问题。
提前感谢您的帮助。
答案 0 :(得分:1)
而不是
format.html { render :action => "new" }
尝试使用
format.html { redirect_to new_admin_girl_path }