0

我有 Rails 模型文章 receive_letters:boolean。而且我的申请中有骨干。在主干视图中,我喜欢它:

<form id="new-article" name="article">
<div class="field">
 <label for="receive_letters">Подписаться на новостную рассылку </label>
 <input type="text" name="receive_letters" id="receive_letters" value="<%= receive_letters %>">
</div>

它工作正常。但是后来我将类型从“文本”更改为“复选框”,它的值 = null。我究竟做错了什么?

4

2 回答 2

0

对于复选框,您还需要从value属性更改为checked属性:

<input type="checkbox" name="receive_letters" id="receive_letters" checked="<%= receive_letters %>">
于 2012-12-02T19:39:32.043 回答
0

修复。

模板(new.jst.ejs):

<input type="checkbox" name="receive_letters" id="receive_letters">

查看(new_view.js.coffee):

events: {
  "click input:checkbox": "check"
  }
check: (e) ->  
  if e.currentTarget.checked == true
    e.currentTarget.value = "true"
  else
    e.currentTarget.value = "false"
于 2012-12-03T18:34:06.610 回答