Class: Thredded::TopicForm
- Inherits:
-
Object
- Object
- Thredded::TopicForm
- Includes:
- ActiveModel::Model
- Defined in:
- app/forms/thredded/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.
-
#messageboard ⇒ Object
readonly
Returns the value of attribute messageboard.
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #category_options ⇒ Object
-
#initialize(params = {}) ⇒ TopicForm
constructor
A new instance of TopicForm.
- #post ⇒ Object
- #preview_path ⇒ Object
- #save ⇒ Object
- #submit_path ⇒ Object
- #topic ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ TopicForm
Returns a new instance of TopicForm.
12 13 14 15 16 17 18 19 20 |
# File 'app/forms/thredded/topic_form.rb', line 12 def initialize(params = {}) @title = params[:title] @category_ids = params[:category_ids] @locked = params[:locked] || false @sticky = params[:sticky] || false @content = params[:content] @user = params[:user] || fail('user is required') @messageboard = params[:messageboard] end |
Instance Attribute Details
#category_ids ⇒ Object
Returns the value of attribute category_ids.
7 8 9 |
# File 'app/forms/thredded/topic_form.rb', line 7 def category_ids @category_ids end |
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'app/forms/thredded/topic_form.rb', line 7 def content @content end |
#locked ⇒ Object
Returns the value of attribute locked.
7 8 9 |
# File 'app/forms/thredded/topic_form.rb', line 7 def locked @locked end |
#messageboard ⇒ Object (readonly)
Returns the value of attribute messageboard.
8 9 10 |
# File 'app/forms/thredded/topic_form.rb', line 8 def @messageboard end |
#sticky ⇒ Object
Returns the value of attribute sticky.
7 8 9 |
# File 'app/forms/thredded/topic_form.rb', line 7 def sticky @sticky end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'app/forms/thredded/topic_form.rb', line 7 def title @title end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'app/forms/thredded/topic_form.rb', line 8 def user @user end |
Class Method Details
Instance Method Details
#category_options ⇒ Object
26 27 28 |
# File 'app/forms/thredded/topic_form.rb', line 26 def .categories.map { |cat| [cat.name, cat.id] } end |
#post ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/forms/thredded/topic_form.rb', line 52 def post @post ||= topic.posts.build( content: content, user: non_null_user, messageboard: ) end |
#preview_path ⇒ Object
64 65 66 |
# File 'app/forms/thredded/topic_form.rb', line 64 def preview_path Thredded::UrlsHelper.() end |
#save ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/forms/thredded/topic_form.rb', line 30 def save return false unless valid? ActiveRecord::Base.transaction do new_topic = !topic.persisted? topic.save! post.save! Thredded::UserTopicReadState.read_on_first_post!(user, post) if new_topic end true end |
#submit_path ⇒ Object
60 61 62 |
# File 'app/forms/thredded/topic_form.rb', line 60 def submit_path Thredded::UrlsHelper.url_for([, topic, only_path: true]) end |
#topic ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'app/forms/thredded/topic_form.rb', line 42 def topic @topic ||= .topics.build( title: title, locked: locked, sticky: sticky, user: non_null_user, categories: topic_categories, ) end |