Class: SubscriptionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- SubscriptionsController
- Defined in:
- app/controllers/subscriptions_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /subscriptions POST /subscriptions.json.
-
#destroy ⇒ Object
DELETE /subscriptions/:topic DELETE /subscriptions/:topic.json.
-
#index ⇒ Object
GET /subscriptions GET /subscriptions.json.
Instance Method Details
#create ⇒ Object
POST /subscriptions POST /subscriptions.json
11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/subscriptions_controller.rb', line 11 def create respond_to do |format| if UserSubscribeTopic.create(topic: topic, user: current_user) format.html { redirect_to '/subscriptions', notice: "You are subscribe #{topic}." } else format.html { render :index } end end end |
#destroy ⇒ Object
DELETE /subscriptions/:topic DELETE /subscriptions/:topic.json
23 24 25 26 27 28 29 |
# File 'app/controllers/subscriptions_controller.rb', line 23 def destroy UserSubscribeTopic.find_by(topic: params[:id], user: current_user).destroy respond_to do |format| format.html { redirect_to '/subscriptions', notice: "You are unsbscribe #{topic}" } format.json { head :no_content } end end |
#index ⇒ Object
GET /subscriptions GET /subscriptions.json
4 5 6 7 |
# File 'app/controllers/subscriptions_controller.rb', line 4 def index @subscriptions = UserSubscribeTopic.where(user: current_user) @subscription = UserSubscribeTopic.new(topic: topic) end |