Class: Homeland::TopicsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#admin?, #authenticate_user!, #authorize_admin!, #authorize_resource!, #current_user, #owner?, #set_seo_meta

Instance Method Details

#createObject

POST /topics POST /topics.xml



64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/homeland/topics_controller.rb', line 64

def create
  @topic = Topic.new(topic_params)
  @topic.user_id = current_user.id

  if @topic.save
    redirect_to(topic_path(@topic.id), notice: t('homeland.topic_created'))
  else
    render action: "new"
  end
end

#destroyObject

DELETE /topics/1 DELETE /topics/1.xml



89
90
91
92
# File 'app/controllers/homeland/topics_controller.rb', line 89

def destroy
  topic.destroy
  redirect_to(topics_path, notice: t('homeland.topic_deleted'))
end

#editObject

GET /topics/1/edit



58
59
60
# File 'app/controllers/homeland/topics_controller.rb', line 58

def edit
  @node = @topic.node
end

#indexObject



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

def index
  @topics = Topic.latest.includes(:user).page(params[:page])

  set_seo_meta(t("homeland.nav.latest"))
end

#newObject



38
39
40
41
42
43
# File 'app/controllers/homeland/topics_controller.rb', line 38

def new
  @topic = Topic.new
  @node = Node.find_by(id: params[:node_id])

  set_seo_meta(t("homeland.nav.new"))
end

#nodeObject



14
15
16
17
18
19
# File 'app/controllers/homeland/topics_controller.rb', line 14

def node
  @node = Node.find(params[:id])
  @topics = @node.topics.latest.includes(:user).page(params[:page])

  render action: "index"
end

#replyObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/homeland/topics_controller.rb', line 45

def reply
  @topic = Topic.find(params[:id])
  @reply = @topic.replies.build(reply_params)
  @reply.user_id = current_user.id
  if @reply.save
    flash[:notice] = t('homeland.reply_created')
  else
    flash[:alert] = @reply.errors.full_messages.join("<br />")
  end
  redirect_to topic_path(params[:id],:anchor => "reply")
end

#showObject



31
32
33
34
35
36
# File 'app/controllers/homeland/topics_controller.rb', line 31

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

  set_seo_meta(@topic.title)
end

#updateObject

PUT /topics/1 PUT /topics/1.xml



77
78
79
80
81
82
83
84
85
# File 'app/controllers/homeland/topics_controller.rb', line 77

def update
  @topic = Topic.find(params[:id])

  if @topic.update_attributes(topic_params)
    redirect_to(topic_path(@topic.id), notice: t('homeland.topic_updated'))
  else
    render action: "edit"
  end
end