0
我正在實施ActiveAdmin來刪除我的應用程序的內容。到現在爲止還挺好。 但我收到錯誤:當我在管理面板中訪問操作「新建」時,無法找到沒有ID和ID的女孩。找不到記錄沒有ID,Rails 4和ActiveAdmin
我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
但是,這並不能解決問題。
在此先感謝您的幫助。
如果卡住
嘗試,'提出girl_params'會告訴你這是怎麼回事。或者你可以使用像pry這樣的調試器。 –
你還沒有告訴我們錯誤發生在哪一行,'new'方法似乎不成問題。 –