Class: Forem::TopicsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/forem/topics_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/forem/topics_controller.rb', line 13

def create
  rawtopic = params[:topic][:subject]
  @topic = Forem::Topic.create({user_id: current_user.id, subject: rawtopic})
  rawposts = params[:topic][:posts_attributes]
  rawposts.each do |raw|
    @topic.posts.create(text: raw[1][:text])
  end
  @topic.save!
  flash[:notice] = "Topic has been created!"
  redirect_to @topic
end

#indexObject



5
6
7
# File 'app/controllers/forem/topics_controller.rb', line 5

def index
  @topics = Forem::Topic.all
end

#newObject



9
10
11
12
# File 'app/controllers/forem/topics_controller.rb', line 9

def new
  @topic = Forem::Topic.new
  @topic.posts.build
end

#showObject



24
25
26
# File 'app/controllers/forem/topics_controller.rb', line 24

def show
  @topic = Forem::Topic.find(params[:id])
end