Class: Homeland::TopicsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Homeland::TopicsController
- Defined in:
- app/controllers/homeland/topics_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /topics POST /topics.xml.
-
#destroy ⇒ Object
DELETE /topics/1 DELETE /topics/1.xml.
-
#edit ⇒ Object
GET /topics/1/edit.
- #index ⇒ Object
- #new ⇒ Object
- #node ⇒ Object
- #reply ⇒ Object
- #show ⇒ Object
-
#update ⇒ Object
PUT /topics/1 PUT /topics/1.xml.
Methods inherited from ApplicationController
#admin?, #authenticate_user!, #authorize_admin!, #authorize_resource!, #current_user, #owner?, #set_seo_meta
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
GET /topics/1/edit
58 59 60 |
# File 'app/controllers/homeland/topics_controller.rb', line 58 def edit @node = @topic.node end |
#index ⇒ Object
8 9 10 11 12 |
# File 'app/controllers/homeland/topics_controller.rb', line 8 def index @topics = Topic.latest.includes(:user).page(params[:page]) (t("homeland.nav.latest")) end |
#new ⇒ Object
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]) (t("homeland.nav.new")) end |
#node ⇒ Object
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 |
#reply ⇒ Object
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..join("<br />") end redirect_to topic_path(params[:id],:anchor => "reply") end |
#show ⇒ Object
31 32 33 34 35 36 |
# File 'app/controllers/homeland/topics_controller.rb', line 31 def show @topic = Topic.find(params[:id]) @replies = replies (@topic.title) end |
#update ⇒ Object
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 |