0

こんな関係を持っている

class User
  include Mongoid::Document
  include Mongoid::Timestamps

  embeds_one :setting
end

そして設定クラス

class Setting
  include Mongoid::Document
  include Mongoid::Timestamps

  embedded_in :user

  field :notify, type: Boolean
end

そして、私は次のようなフォームを持っています:

<% form_for current_user.setting || current_user.build_setting, :html => {:class => 'well'} do |f| %>
  Notificar: <%= f.check_box :notify, :class => 'check' %>

  <div class="form-actions">
    <%= f.submit "Salvar" %>
  </div>
<% end %>

フォームページにアクセスすると、フォームが表示されません。私はそれsettingが nil であるか、またはそのようなものであると思われます...
何が欠けていますか?
君たちありがとう

4

1 に答える 1

3

の前に等号がありませんform_for

<%= form_for # ... %>

form_forヘルパーはブロック内のすべてのものをレンダリングし、フォーム タグを追加して、html を返します。それを表示するには、返された文字列を表示したいことを eRB に伝える必要があります。したがって、等号がない場合、出力は表示されません。

于 2012-07-02T12:47:35.450 に答える