2014-04-02 23:40:05 +08:00
|
|
|
class SubscribesController < ApplicationController
|
2014-04-07 22:56:21 +08:00
|
|
|
|
2014-04-03 16:49:59 +08:00
|
|
|
def index
|
|
|
|
end
|
2014-04-07 22:56:21 +08:00
|
|
|
|
2014-04-02 23:40:05 +08:00
|
|
|
def create
|
|
|
|
subscribe = Subscribe.find_or_initialize_by(email: params[:email])
|
|
|
|
subscribe.enable = true
|
|
|
|
|
|
|
|
if subscribe.save
|
|
|
|
render :json => { success: true }
|
|
|
|
else
|
|
|
|
render :json => { success: false, message: subscribe.errors.full_messages.join(", ")}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-03 16:49:59 +08:00
|
|
|
def cancel
|
2014-04-07 22:56:21 +08:00
|
|
|
subscribe = Subscribe.find_or_initialize_by(email: params[:email])
|
|
|
|
subscribe.enable = false
|
|
|
|
subscribe.save
|
2014-04-02 23:40:05 +08:00
|
|
|
|
2014-04-03 16:49:59 +08:00
|
|
|
flash[:notice] = "退订成功: #{params[:email]}"
|
2014-04-02 23:40:05 +08:00
|
|
|
render :json => { success: true }
|
|
|
|
end
|
2014-04-03 16:49:59 +08:00
|
|
|
|
2014-04-02 23:40:05 +08:00
|
|
|
end
|