Class: Thredded::PrivateTopicForm
- Inherits:
-
Object
- Object
- Thredded::PrivateTopicForm
- Includes:
- ActiveModel::Model
- Defined in:
- app/forms/thredded/private_topic_form.rb
Overview
rubocop:disable Metrics/ClassLength
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.
- #user_names ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ PrivateTopicForm
constructor
A new instance of PrivateTopicForm.
- #post ⇒ Object
- #preview_path ⇒ Object
- #save ⇒ Object
- #submit_path ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ PrivateTopicForm
Returns a new instance of PrivateTopicForm.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/forms/thredded/private_topic_form.rb', line 24 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] @user_names = params[:user_names] end |
Instance Attribute Details
#category_ids ⇒ Object
Returns the value of attribute category_ids.
10 11 12 |
# File 'app/forms/thredded/private_topic_form.rb', line 10 def category_ids @category_ids end |
#content ⇒ Object
Returns the value of attribute content.
10 11 12 |
# File 'app/forms/thredded/private_topic_form.rb', line 10 def content @content end |
#locked ⇒ Object
Returns the value of attribute locked.
10 11 12 |
# File 'app/forms/thredded/private_topic_form.rb', line 10 def locked @locked end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
19 20 21 |
# File 'app/forms/thredded/private_topic_form.rb', line 19 def params @params end |
#private_topic ⇒ Object
Returns the value of attribute private_topic.
10 11 12 |
# File 'app/forms/thredded/private_topic_form.rb', line 10 def private_topic @private_topic end |
#sticky ⇒ Object
Returns the value of attribute sticky.
10 11 12 |
# File 'app/forms/thredded/private_topic_form.rb', line 10 def sticky @sticky end |
#title ⇒ Object
Returns the value of attribute title.
10 11 12 |
# File 'app/forms/thredded/private_topic_form.rb', line 10 def title @title end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
19 20 21 |
# File 'app/forms/thredded/private_topic_form.rb', line 19 def user @user end |
#user_ids ⇒ Object
Returns the value of attribute user_ids.
10 11 12 |
# File 'app/forms/thredded/private_topic_form.rb', line 10 def user_ids @user_ids end |
#user_names ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'app/forms/thredded/private_topic_form.rb', line 77 def user_names @user_names ||= Thredded.user_class.where(id: user_ids).pluck(Thredded.user_name_column).map do |name| if name.include?(',') "\"#{name}\"" else name end end.join(', ') end |
Class Method Details
.model_name ⇒ Object
36 37 38 |
# File 'app/forms/thredded/private_topic_form.rb', line 36 def self.model_name Thredded::PrivateTopic.model_name end |
Instance Method Details
#post ⇒ Object
62 63 64 65 66 67 |
# File 'app/forms/thredded/private_topic_form.rb', line 62 def post @post ||= private_topic.posts.build( content: content, user: non_null_user ) end |
#preview_path ⇒ Object
73 74 75 |
# File 'app/forms/thredded/private_topic_form.rb', line 73 def preview_path Thredded::UrlsHelper.preview_new_private_topic_path end |
#save ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/forms/thredded/private_topic_form.rb', line 40 def save @user_ids ||= [] @user_ids += Thredded.user_class.where(Thredded.user_name_column => parse_names(user_names)).pluck(:id) return false unless valid? ActiveRecord::Base.transaction do private_topic.save! post.save! end true end |
#submit_path ⇒ Object
69 70 71 |
# File 'app/forms/thredded/private_topic_form.rb', line 69 def submit_path Thredded::UrlsHelper.url_for([private_topic, only_path: true]) end |