不想以一种形式显示neo4j关系 [英] Don't want to display neo4j relations in a form

查看:211
本文介绍了不想以一种形式显示neo4j关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在当前应用程序中使用neo4j,这是我第一次使用此数据库,因此我有很多疑问.现在最重要的是以下内容.

I'm using neo4j in my current app and it is my first time with this database, then I have a lot of doubts. The most important now is the following.

我正在自定义输入表单(如您可能在

I'm customizing my input forms (as you may see in this question I asked) and here is one of my models:

class Contact 
  include Neo4j::ActiveNode
  property :first_name, type: String
  property :surname, type: String
  property :email, type: String
  property :phones, type: String
  has_one :in, :address, type: :HAS_ADDRESS
  has_one :in, :title, type: :HAS_TITLE
  has_one :in, :gender, type: :HAS_GENDER
end

据我所知,这些关系会在我的模型中创建自己的属性,因为在生成脚手架时,即使未在模型中显式创建它们,属性:address,:title和:gender都处于形式中.

As I understand things, these relations create their own properties in my model, because when I generate my scaffold the properties :address, :title and :gender are all in the form, even if they are not explicitly created in my model.

碰巧其中某些属性不应该显示. :address就是这种情况,我将在适当的情况下部分渲染它.

It happens that some of these properties should not be exhibited. This is the case of :address, which I'll render in a partial in the appropriate situations.

默认情况下,neo4j关系定义的其他属性:gender和:title应该显示为HTML选择.

The other properties defined by neo4j relations by default , :gender and :title, should be exhibited as HTML selects.

这是我的问题:当我以编程方式创建表单时,如何区分所描述的属性和由表单生成器级别的关系所生成的属性?

换句话说,我应该在我的** lib/templates/erb/scaffold/_form.html.erb 中放入什么以保证其中的某些属性不显示而另一些属性显示为HTML选择标签?**

In other words, what should I put in my **lib/templates/erb/scaffold/_form.html.erb to guarantee that some of these properties are not exhibited and others are exhibited as HTML select tags?**

我是否要创建像is_displayable这样的方法?和is_select?属性中,但是我真的不知道该在哪里做,因为这些属性未在任何地方显式声明.

I though about creating some kind of methods like is_displayable? and is_select? in the property, but I really don't know where I may do so, because these properties are not explicitly declared anywhere.

对此有何建议?

推荐答案

我不会说这些关联会创建属性.关联(has_onehas_many)和属性在Ruby模型类及其对象上创建方法.

I wouldn't say that the associations create properties. Associations (has_one and has_many) and properties create methods on your Ruby model class and it's objects.

此外,您可以通过多种方式来执行此操作,这些方式都不是真正针对neo4j gem的(如果您这样做的话,也不是针对ActiveRecord的).

That aside, you could do this in a number of ways, none of which are really specific to the neo4j gem (nor would it be specific to ActiveRecord if you were doing that).

您可能在视图中有一个要迭代的数组.您可以在模型中有一个常量,该常量定义可编辑的常量,然后类似于您的建议定义一个is_editable?.

You could have an array in your view which you iterate over. You could have a constant in the model which defines which are editable and then define a is_editable? similarly to what you suggest.

但可能不会在Rails的model-view-controller设置中推荐任何一个.控制器通常负责执行 strong参数,因此您可能需要一个常量在那里,它既可以用作传递给视图的变量,也可以用作在提交值时验证值的原因(因为您的视图未显示这些字段,这并不意味着恶意方无法不能创建自己的表单或使用类似Postman Chrome插件的插件来提交)

But probably neither of those would be recommended in the model-view-controller setup in Rails. Controllers are generally responsible for enforcing strong parameters, so you'd probably want a constant in there which can be used both as a variable passed down to the view as well as using it to verify values as they are being submitted (because just because your view doesn't show those fields, it doesn't mean a malicious party couldn't create their own form or submit with something like the Postman plugin for Chrome)

这篇关于不想以一种形式显示neo4j关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆