我正在尝试在rails 中的belongs_to 模型关联中构建一个has_many 模型。关联是正确的,但显示错误“必须存在”。我尝试添加可选项:true,但它似乎不起作用。
楷模
class User::Product < ApplicationRecord
has_one: :promo_code
end
class User::PromoCode < ApplicationRecord
belongs_to: :product, optional: true
accepts_nested_attributes_for :product
end
Run Code Online (Sandbox Code Playgroud)
促销代码控制器
def new
@promo_code = User::PromoCode.new
@product.build_product
end
def create
@promo_code = User::PromoCode.new(promo_code_params)
@promo_code.save
end
def promo_code_params
params.require(:user_promo_code).permit(:product_id, :product_attributes => [:name])
end
Run Code Online (Sandbox Code Playgroud)
形式
form_with(model: promo_code) do |form|
form.fields_for :product do |f|
f.text_field :name
end
end
Run Code Online (Sandbox Code Playgroud)
当表单保存时,出现错误,提示“必须存在”,我假设它指的是belongs_to中的外键。
我可能做错了什么有什么想法吗?我认为上面的代码是我关于这个问题的唯一相关代码。
我正在使用DrawPad 示例在 Model UIDelegate 中创建一个服装组件。但是,由于某种原因,我收到了错误UIDefaults.getUI() failed: no ComponentUI class。我什至不确定我是否正确实施了 Model UIDelegate。但是为什么我会收到这个错误?
主要的
public class Main {
static JFrame frame;
static JButton clearButton;
static DrawPad drawPad;
public static void main(String[] args) {
UIManager.put("DrawPadUI", "BasicDrawPadUI");
frame = new JFrame();
drawPad = new DrawPad();
clearButton = new JButton("Clear");
frame.add(drawPad, BorderLayout.CENTER);
clearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Graphics g = frame.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, frame.getWidth(), frame.getHeight());
}
});
frame.add(clearButton, BorderLayout.SOUTH); …Run Code Online (Sandbox Code Playgroud) 我无法从 Rails 访问 Google Analytics API。即使我已经设置了服务帐户,我仍然获得足够的权限。
我创建了一个服务帐户:
拥有服务帐户并拥有秘密 JSON 文件和电子邮件后。然后我去谷歌分析:
一旦我有了这个,几乎可以使用以下代码: https: //gist.github.com/CoryFoy/9edf1e039e174c00c209e930a1720ce0来获取报告。
但我不断得到forbidden: User does not have sufficient permissions for this profile。即使当我尝试获取 access_token 并在 javascript 中使用它时:
gapi.analytics.auth.authorize({
serverAuth: {
access_token: 'accessToken'
}
});
Run Code Online (Sandbox Code Playgroud)
我得到:
error:{
code: 403
errors: [
{
domain: "global"
message: "User does not have sufficient permissions for this profile."
reason: "insufficientPermissions"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?这曾经有效,我从来没有遇到过问题,但由于某种原因它停止工作了。任何指导将不胜感激。
谢谢你! …
javascript google-analytics ruby-on-rails google-api-client google-analytics-4