Class: Thredded::PostForm
- Inherits:
-
Object
- Object
- Thredded::PostForm
- Defined in:
- app/forms/thredded/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: {}) ⇒ PostForm
constructor
A new instance of PostForm.
- #preview_path ⇒ Object
- #save ⇒ Object
- #submit_path ⇒ Object
Constructor Details
#initialize(user:, topic:, post: nil, post_params: {}) ⇒ PostForm
Returns a new instance of PostForm.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/forms/thredded/post_form.rb', line 16 def initialize(user:, topic:, post: nil, post_params: {}) @messageboard = topic. @topic = topic @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?), messageboard: topic. ) end |
Instance Attribute Details
#post ⇒ Object (readonly)
Returns the value of attribute post.
5 6 7 |
# File 'app/forms/thredded/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/post_form.rb', line 5 def topic @topic end |
Class Method Details
.for_persisted(post) ⇒ Object
32 33 34 |
# File 'app/forms/thredded/post_form.rb', line 32 def self.for_persisted(post) new(user: post.user, topic: post.postable, post: post) end |
Instance Method Details
#preview_path ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/forms/thredded/post_form.rb', line 40 def preview_path if @post.persisted? Thredded::UrlsHelper.(@messageboard, @topic, @post) else Thredded::UrlsHelper.(@messageboard, @topic) end end |
#save ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/forms/thredded/post_form.rb', line 48 def save return false unless @post.valid? was_persisted = @post.persisted? @post.save! Thredded::UserTopicReadState.touch!(@post.user.id, @post) unless was_persisted true end |
#submit_path ⇒ Object
36 37 38 |
# File 'app/forms/thredded/post_form.rb', line 36 def submit_path Thredded::UrlsHelper.url_for([@messageboard, @topic, @post, only_path: true]) end |