Class: Thredded::PrivateTopicForm
- Inherits:
-
Object
- Object
- Thredded::PrivateTopicForm
- Includes:
- ActiveModel::Model
- Defined in:
- app/forms/thredded/private_topic_form.rb
Instance Attribute Summary collapse
-
#category_ids ⇒ Object
Returns the value of attribute category_ids.
-
#content ⇒ Object
Returns the value of attribute content.
-
#locked ⇒ Object
Returns the value of attribute locked.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#private_topic ⇒ Object
Returns the value of attribute private_topic.
-
#sticky ⇒ Object
Returns the value of attribute sticky.
-
#title ⇒ Object
Returns the value of attribute title.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#user_ids ⇒ Object
Returns the value of attribute user_ids.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ PrivateTopicForm
constructor
A new instance of PrivateTopicForm.
- #post ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ PrivateTopicForm
Returns a new instance of PrivateTopicForm.
22 23 24 25 26 27 28 29 30 31 |
# File 'app/forms/thredded/private_topic_form.rb', line 22 def initialize(params = {}) @params = params @title = params[:title] @category_ids = params[:category_ids] || [] @user_ids = params[:user_ids] || [] @user = params[:user] || fail('user is required') @locked = params[:locked] @sticky = params[:sticky] @content = params[:content] end |
Instance Attribute Details
#category_ids ⇒ Object
Returns the value of attribute category_ids.
9 10 11 |
# File 'app/forms/thredded/private_topic_form.rb', line 9 def category_ids @category_ids end |
#content ⇒ Object
Returns the value of attribute content.
9 10 11 |
# File 'app/forms/thredded/private_topic_form.rb', line 9 def content @content end |
#locked ⇒ Object
Returns the value of attribute locked.
9 10 11 |
# File 'app/forms/thredded/private_topic_form.rb', line 9 def locked @locked end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
18 19 20 |
# File 'app/forms/thredded/private_topic_form.rb', line 18 def params @params end |
#private_topic ⇒ Object
Returns the value of attribute private_topic.
9 10 11 |
# File 'app/forms/thredded/private_topic_form.rb', line 9 def private_topic @private_topic end |
#sticky ⇒ Object
Returns the value of attribute sticky.
9 10 11 |
# File 'app/forms/thredded/private_topic_form.rb', line 9 def sticky @sticky end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'app/forms/thredded/private_topic_form.rb', line 9 def title @title end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
18 19 20 |
# File 'app/forms/thredded/private_topic_form.rb', line 18 def user @user end |
#user_ids ⇒ Object
Returns the value of attribute user_ids.
9 10 11 |
# File 'app/forms/thredded/private_topic_form.rb', line 9 def user_ids @user_ids end |
Class Method Details
.model_name ⇒ Object
33 34 35 |
# File 'app/forms/thredded/private_topic_form.rb', line 33 def self.model_name Thredded::PrivateTopic.model_name end |
Instance Method Details
#post ⇒ Object
56 57 58 59 60 61 |
# File 'app/forms/thredded/private_topic_form.rb', line 56 def post @post ||= private_topic.posts.build( content: content, user: non_null_user ) end |
#save ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/forms/thredded/private_topic_form.rb', line 37 def save return false unless valid? ActiveRecord::Base.transaction do private_topic.save! post.save! end true end |