Class: Thredded::CreateMessageboard
- Inherits:
-
Object
- Object
- Thredded::CreateMessageboard
- Defined in:
- app/commands/thredded/create_messageboard.rb
Overview
Creates a new messageboard and seeds it with a topic.
Instance Method Summary collapse
- #first_topic_content ⇒ Object
- #first_topic_title ⇒ Object
-
#initialize(messageboard, user) ⇒ CreateMessageboard
constructor
A new instance of CreateMessageboard.
-
#run ⇒ boolean
True if the messageboard was created and seeded with a topic successfully.
Constructor Details
#initialize(messageboard, user) ⇒ CreateMessageboard
Returns a new instance of CreateMessageboard.
8 9 10 11 |
# File 'app/commands/thredded/create_messageboard.rb', line 8 def initialize(, user) @messageboard = @user = user end |
Instance Method Details
#first_topic_content ⇒ Object
36 37 38 39 40 |
# File 'app/commands/thredded/create_messageboard.rb', line 36 def first_topic_content <<~MARKDOWN #{I18n.t('thredded.messageboard_first_topic.content', thredded_version: Thredded::VERSION)} MARKDOWN end |
#first_topic_title ⇒ Object
32 33 34 |
# File 'app/commands/thredded/create_messageboard.rb', line 32 def first_topic_title I18n.t('thredded.messageboard_first_topic.title') end |
#run ⇒ boolean
Returns true if the messageboard was created and seeded with a topic successfully.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/commands/thredded/create_messageboard.rb', line 14 def run Thredded::Messageboard.transaction do fail ActiveRecord::Rollback unless @messageboard.save topic = Thredded::Topic.create!( messageboard: @messageboard, user: @user, title: first_topic_title ) Thredded::Post.create!( messageboard: @messageboard, user: @user, postable: topic, content: first_topic_content ) true end end |