ページにコメント追加フォームを作成しようとしていますが、同じページに複数回表示する必要があります。
これが私のモデルです。私は Mongoid 3.0 を使用していますが、それは問題ではないと思います。モデルは正しく機能しています。
class Project
include Mongoid::Document
...
embeds_many :comments, :as => :commentable
...
end
class Suggestion
include Mongoid::Document
...
embeds_many :comments, :as => :commentable
...
end
class Comment
include Mongoid::Document
embedded_in :commentable, :polymorphic => true
...
end
私はこれらのルートを持っています
suggestion_comments POST /suggestions/:suggestion_id/comments(.:format) comments#create
project_comments POST /projects/:project_id/comments(.:format) comments#create
私は次の方法でフォームを呼び出しています:
= render partial: "comments/new", locals: { :commentable => stream.project }
= render partial: "comments/new", locals: { :commentable => stream.suggestion }
form_for を作成するにはどうすればよいですか? これを試しましたが、うまくいきません。また、これをページに複数回表示する必要があるため、id
ページに重複する CSS があると、このページの JavaScript で問題が発生します。
= form_for commentable.comments, remote: true do |f|
%fieldset
.control-group
.controls
= f.text_area :content, :required => true, :placeholder => "Add a comment...", :maxlength => "1000"
.form-actions
= f.submit "Post"