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:



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

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

Class Method Details

.model_nameObject



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

def self.model_name
  Thredded::Topic.model_name
end

Instance Method Details

#category_optionsObject



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

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

#edit_pathObject



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

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

#messageboard_optionsObject



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

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

#messageboard_pathObject



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

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

#pathObject



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

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

#persisted?Boolean

Returns:

  • (Boolean)


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

def persisted?
  true
end

#saveObject



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

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