Ruby / Rails性别代词

你们怎么处理这些? 比较2个人,但使用他们的性别特定代词? “鲍勃喜欢斯泰西。他一直渴望她和她的长发。她不喜欢鲍勃,还有他那令人毛骨悚然的目光……”

因此,Bob是数据库中的实体,Stacy也是如此。 bob = User.find_by_name('Bob')stacy = User.find_by_name('Stacy')bob.gender返回male, stacy.gender返回female。

以上引用也来自数据库中的实体。 Match.find(23).body 。 我想在数据库中放入一些通用的东西,并使其可填写,但它似乎不起作用。 @p1.first_name likes @p2.first_name. @p1.She has always longed for @p2.her, and @p2.her_p long hair. @p2.She doesn't like @p2.first_name, and @p2.her_p creepy stares... @p1.first_name likes @p2.first_name. @p1.She has always longed for @p2.her, and @p2.her_p long hair. @p2.She doesn't like @p2.first_name, and @p2.her_p creepy stares...在这里,我有一些方法以女性代名词为名,并返回实际。

在控制器中, @dislike = Match.find(23).body@p1 = bob@p2 = stacy对吗?

在视图中,

那样不行。 我也看了gsub,并据此剥离。 我可以让它发挥作用。 我只是好奇其他人如何处理这种情况,或者我是否已经非常复杂。

如果您正在使用数据库,只需在“性别”的Name表中添加一列,如果您要使用布尔字段,那么您可以执行..

 name_a = some_db_query_for_name if name_a.gender = true: a = "she" else: a = "he" 

然后在你的模板中引用

 @name_a likes @name_b, @a is ... 

对不起,它不是ruby / rails代码,但我看到了问题,这似乎是接近它的最佳方式。

 def rend(p1, p2) body = self.body body = body.gsub(/p1.first_name/, p1.first_name) body = body.gsub(/p2.first_name/, p2.first_name) if p1.gender == 'male' body = body.gsub(/p1.she/, 'he') body = body.gsub(/p1.her_p/, 'his') body = body.gsub(/p1.her/, 'him') body = body.gsub(/p1.herself/, 'himself') body = body.gsub(/p1.hers/, 'his') body = body.gsub(/p1.She/, 'He') body = body.gsub(/p1.Her_p/, 'His') body = body.gsub(/p1.Her/, 'Him') body = body.gsub(/p1.Herself/, 'Himself') body = body.gsub(/p1.Hers/, 'His') end if p1.gender == 'female' body = body.gsub(/p1.she/, 'she') body = body.gsub(/p1.her_p/, 'her') body = body.gsub(/p1.her/, 'her') body = body.gsub(/p1.herself/, 'herself') body = body.gsub(/p1.hers/, 'hers') body = body.gsub(/p1.She/, 'She') body = body.gsub(/p1.Her_p/, 'Her') body = body.gsub(/p1.Her/, 'Her') body = body.gsub(/p1.Herself/, 'Herself') body = body.gsub(/p1.Hers/, 'Hers') end if p2.gender == 'male' body = body.gsub(/p2.she/, 'he') body = body.gsub(/p2.her_p/, 'his') body = body.gsub(/p2.her/, 'him') body = body.gsub(/p2.herself/, 'himself') body = body.gsub(/p2.hers/, 'his') body = body.gsub(/p2.She/, 'He') body = body.gsub(/p2.Her_p/, 'His') body = body.gsub(/p2.Her/, 'Him') body = body.gsub(/p2.Herself/, 'Himself') body = body.gsub(/p2.Hers/, 'His') end if p2.gender == 'female' body = body.gsub(/p2.she/, 'she') body = body.gsub(/p2.her_p/, 'her') body = body.gsub(/p2.her/, 'her') body = body.gsub(/p2.herself/, 'herself') body = body.gsub(/p2.hers/, 'hers') body = body.gsub(/p2.She/, 'She') body = body.gsub(/p2.Her_p/, 'Her') body = body.gsub(/p2.Her/, 'Her') body = body.gsub(/p2.Herself/, 'Herself') body = body.gsub(/p2.Hers/, 'Hers') end body end