Class: TopicsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TopicsController
- Defined in:
- app/controllers/topics_controller.rb
Instance Method Summary collapse
-
#show ⇒ Object
GET /topic/:name GET /topic/:name.json.
-
#subscribe ⇒ Object
POST /topic/:name/subscribe POST /topic/:name/subscribe.json.
-
#unsubscribe ⇒ Object
DELETE /topic/:name/subscribe DELETE /topic/:name/subscribe.json.
Instance Method Details
#show ⇒ Object
GET /topic/:name GET /topic/:name.json
4 5 6 |
# File 'app/controllers/topics_controller.rb', line 4 def show @messages = Message.topic_of(topic) end |
#subscribe ⇒ Object
POST /topic/:name/subscribe POST /topic/:name/subscribe.json
10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/topics_controller.rb', line 10 def subscribe respond_to do |format| if UserSubscribeTopic.create(topic: topic, user: current_user) format.html { redirect_to topic_path(topic), notice: "You are subscribe it." } else format.html { render :index } end end end |
#unsubscribe ⇒ Object
DELETE /topic/:name/subscribe DELETE /topic/:name/subscribe.json
22 23 24 25 26 27 28 |
# File 'app/controllers/topics_controller.rb', line 22 def unsubscribe UserSubscribeTopic.find_by(topic: params[:id], user: current_user).destroy respond_to do |format| format.html { redirect_to topic_path(topic), notice: "You are unsubscribe it." } format.json { head :no_content } end end |