gpt4 book ai didi

mysql - STI、子类和失败的验证

转载 作者:行者123 更新时间:2023-11-29 00:05:44 25 4
gpt4 key购买 nike

我很难弄明白这到底是怎么回事。

我有一个模型 Page,它有两个子类,分别称为 QeopPage 和 GymPage。我正在尝试创建一个 gympage,但两个类中的验证一直失败,并显示 'Validation failed: Title can't be blank, Meta description can't be blank'

class GymPage < Page
self.set_table_name="pages"

validates :meta_description, presence:true

end

class Page < ActiveRecord::Base
validates :title, :presence=>true

end

我认为这可能是参数问题,但我的服务器日志中没有任何迹象表明这一点。我可以在控制台中制作一个健身页面....这是相关的服务器日志片段

Parameters: {"utf8"=>"✓", "authenticity_token"=>"ULWHNAM71V3T+tEgYFaJfWtIQ7twYwktmdo6OSduiYE=", "gym_page"=>{"meta_title"=>"esfwef", "meta_description"=>"wefwefwef", "title"=>"wefwefwef", "body"=>"wefwef", "slug"=>"about", "asset_attachment_title"=>""}, "commit"=>"Update page", "venue_id"=>"venue_one"}
Admin Load (0.4ms) SELECT `admins`.* FROM `admins` WHERE `admins`.`id` = 633 ORDER BY `admins`.`id` ASC LIMIT 1
Venue Load (0.5ms) SELECT `venues`.* FROM `venues` WHERE `venues`.`slug` = 'mitre-passage-8754d82e-8eeb-4d9f-91e4-c13b3661991c' ORDER BY venues.title ASC LIMIT 1
(0.2ms) BEGIN
Admin Load (0.4ms) SELECT `admins`.* FROM `admins` ORDER BY `admins`.`id` ASC LIMIT 1
Admin Load (0.3ms) SELECT `admins`.* FROM `admins` WHERE `admins`.`id` = 2 LIMIT 1
Banner Load (0.3ms) SELECT `banners`.* FROM `banners` WHERE `banners`.`id` IS NULL LIMIT 1
CACHE (0.0ms) SELECT `banners`.* FROM `banners` WHERE `banners`.`id` IS NULL LIMIT 1
(0.2ms) ROLLBACK
Completed 422 Unprocessable Entity in 998ms

我应该补充一点, Controller 按预期工作 - 参数传递正确。

这到底是怎么回事?!

更新

Controller 代码

  def create 
@gym_page = GymPage.new(params[:gym_page_params])
@gym_page.admin=current_admin
if @gym_page.save!
flash[:notice] = 'Page created'
redirect_to admin_venue_gym_pages_path(@venue)
else
flash[:error] = 'There was an error'
render :new
end
end

最佳答案

根据请求,健身房页面属性在 gym_page 内部传递,因此您需要在 Controller 中执行以下操作

@gym_page = GymPage.new(params[:gym_page])

关于mysql - STI、子类和失败的验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27537276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com