Class: Thredded::PrivatePostForm
- Inherits:
-
Object
- Object
- Thredded::PrivatePostForm
- Defined in:
- app/forms/thredded/private_post_form.rb
Instance Attribute Summary collapse
-
#post ⇒ Object
readonly
Returns the value of attribute post.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user:, topic:, post: nil, post_params: {}) ⇒ PrivatePostForm
constructor
A new instance of PrivatePostForm.
- #preview_path ⇒ Object
- #save ⇒ Object
- #submit_path ⇒ Object
Constructor Details
#initialize(user:, topic:, post: nil, post_params: {}) ⇒ PrivatePostForm
Returns a new instance of PrivatePostForm.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/forms/thredded/private_post_form.rb', line 16 def initialize(user:, topic:, post: nil, post_params: {}) @topic = topic @post = post ? post : topic.posts.build user ||= Thredded::NullUser.new if post_params.include?(:quote_post) post_params[:content] = Thredded::ContentFormatter.quote_content(post_params.delete(:quote_post).content) end @post.attributes = post_params.merge(user: (user unless user.thredded_anonymous?)) end |
Instance Attribute Details
#post ⇒ Object (readonly)
Returns the value of attribute post.
5 6 7 |
# File 'app/forms/thredded/private_post_form.rb', line 5 def post @post end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
5 6 7 |
# File 'app/forms/thredded/private_post_form.rb', line 5 def topic @topic end |
Class Method Details
.for_persisted(post) ⇒ Object
28 29 30 |
# File 'app/forms/thredded/private_post_form.rb', line 28 def self.for_persisted(post) new(user: post.user, topic: post.postable, post: post) end |
Instance Method Details
#preview_path ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/forms/thredded/private_post_form.rb', line 36 def preview_path if @post.persisted? Thredded::UrlsHelper.private_topic_private_post_preview_path(@topic, @post) else Thredded::UrlsHelper.preview_new_private_topic_private_post_path(@topic) end end |
#save ⇒ Object
44 45 46 47 48 |
# File 'app/forms/thredded/private_post_form.rb', line 44 def save return false unless @post.valid? @post.save! true end |
#submit_path ⇒ Object
32 33 34 |
# File 'app/forms/thredded/private_post_form.rb', line 32 def submit_path Thredded::UrlsHelper.url_for([@topic, @post, only_path: true]) end |