Class: Thredded::EditTopicForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/forms/thredded/edit_topic_form.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user:, topic:) ⇒ EditTopicForm

Returns a new instance of EditTopicForm.

Parameters:


13
14
15
16
# File 'app/forms/thredded/edit_topic_form.rb', line 13

def initialize(user:, topic:)
  @user = user
  @topic = topic
end

Class Method Details

.model_nameObject


18
19
20
# File 'app/forms/thredded/edit_topic_form.rb', line 18

def self.model_name
  Thredded::Topic.model_name
end

Instance Method Details

#category_optionsObject


22
23
24
# File 'app/forms/thredded/edit_topic_form.rb', line 22

def category_options
  @topic.messageboard.categories.map { |cat| [cat.name, cat.id] }
end

#edit_pathObject


44
45
46
# File 'app/forms/thredded/edit_topic_form.rb', line 44

def edit_path
  Thredded::UrlsHelper.edit_messageboard_topic_path(@topic.messageboard, @topic)
end

#messageboard_optionsObject


26
27
28
# File 'app/forms/thredded/edit_topic_form.rb', line 26

def messageboard_options
  @user.thredded_can_write_messageboards.map { |messageboard| [messageboard.name, messageboard.id] }
end

#messageboard_pathObject


48
49
50
# File 'app/forms/thredded/edit_topic_form.rb', line 48

def messageboard_path
  Thredded::UrlsHelper.messageboard_topics_path(@topic.messageboard)
end

#pathObject


40
41
42
# File 'app/forms/thredded/edit_topic_form.rb', line 40

def path
  Thredded::UrlsHelper.messageboard_topic_path(@topic.messageboard, @topic)
end

#persisted?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/forms/thredded/edit_topic_form.rb', line 36

def persisted?
  true
end

#saveObject


30
31
32
33
34
# File 'app/forms/thredded/edit_topic_form.rb', line 30

def save
  return false unless valid?
  @topic.save!
  true
end