小编bru*_*zrk的帖子

有什么方法可以在 django 模板中允许 \n 吗?(引导弹出)

我有这个字符串

{{contact.info}}
Run Code Online (Sandbox Code Playgroud)

该值是:

name teste\nteste@teste.com.br\n(11) 11111-1111\n(0) 12312-3123\n(12) 12312-3123\n
Run Code Online (Sandbox Code Playgroud)

在 html 我想看到它:

name teste
teste@teste.com.br<br>
(11) 11111-1111
(10) 12312-3123
(12) 12312-3123
Run Code Online (Sandbox Code Playgroud)

有什么办法吗?

python django django-templates popover twitter-bootstrap

4
推荐指数
2
解决办法
8187
查看次数

更新时如何删除has_many关系?

我有两个表,例如:

table_one n x 1 table_two
Run Code Online (Sandbox Code Playgroud)

但是,table_two有许多table_one元素。

楷模:

class TableOne < ActiveRecord::Base
  belongs_to :table_two
end

class TableTwo < ActiveRecord::Base
  has_many :tables_one, class_name 'TableOne'
end
Run Code Online (Sandbox Code Playgroud)

我想table_onetable_two更新之前自动删除其中的所有元素(之前)

ps:或者,正确的位置在table_one.table_two.delete_all哪里?

更新1

该命令:

table_two = TableTwo.last
table_two.tables_one = [TableOne.new(<attributes>), TableOne.new(<attributes>, TableOne.new(<attributes>]
table_two.save
Run Code Online (Sandbox Code Playgroud)

应该删除table_two中所有现有的table_one,然后添加三个新的table_one。

ruby activerecord ruby-on-rails-4

1
推荐指数
1
解决办法
48
查看次数