添加订阅取消功能
This commit is contained in:
parent
51ad5412cf
commit
fed92dd16b
|
@ -0,0 +1,10 @@
|
|||
@app.controller 'SubscribesController', [ '$scope', '$http', ($scope, $http)->
|
||||
$scope.cancel = ()->
|
||||
$http
|
||||
url: '/subscribes/cancel'
|
||||
method: 'POST'
|
||||
params:
|
||||
email: $scope.email
|
||||
.success (res)->
|
||||
window.location = '/'
|
||||
]
|
|
@ -1,4 +1,6 @@
|
|||
class SubscribesController < ApplicationController
|
||||
def index
|
||||
end
|
||||
def create
|
||||
subscribe = Subscribe.find_or_initialize_by(email: params[:email])
|
||||
subscribe.enable = true
|
||||
|
@ -10,12 +12,14 @@ class SubscribesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
def cancel
|
||||
if subscribe = Subscribe.where(email: params[:email]).first
|
||||
subscribe.enable = false
|
||||
subscribe.save
|
||||
end
|
||||
|
||||
flash[:notice] = "退订成功: #{params[:email]}"
|
||||
render :json => { success: true }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -53,6 +53,11 @@ html
|
|||
i.fi-torso
|
||||
| 关于我
|
||||
section.main-section ng-app="app"
|
||||
- flash.each do |name, msg|
|
||||
- if msg.is_a?(String)
|
||||
div class=("alert-box #{name == :notice ? "success" : "alert"}") data-alert=""
|
||||
= content_tag :div, msg
|
||||
a.close href="#" ×
|
||||
= yield
|
||||
= render "layouts/footer"
|
||||
a.exit-off-canvas
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
h1 Subscribes#create
|
||||
p Find me in app/views/subscribes/create.html.slim
|
|
@ -1,2 +0,0 @@
|
|||
h1 Subscribes#destroy
|
||||
p Find me in app/views/subscribes/destroy.html.slim
|
|
@ -0,0 +1,9 @@
|
|||
.row
|
||||
.large-9.large-centered.columns
|
||||
h2 退订服务
|
||||
hr
|
||||
form action='' ng-controller='SubscribesController'
|
||||
.row
|
||||
.small-12.large-6.columns
|
||||
= text_field_tag :email, nil, placeholder: 'your@email.com', 'ng-model' => 'email'
|
||||
button ng-click="cancel()" 退订
|
|
@ -28,6 +28,8 @@ class NewPostWorker
|
|||
<p>#{ENV['SITE_NAME']} 新博客到了: #{title}</p>
|
||||
|
||||
<p>具体内容请访问: http://yafeilee.me</p>
|
||||
|
||||
<p><a href="http://yafeilee.me/unsubscribe?id=5F46EF">点此退订</a></p>
|
||||
EOF
|
||||
}
|
||||
return response
|
||||
|
|
|
@ -15,7 +15,12 @@ WBlog::Application.routes.draw do
|
|||
|
||||
|
||||
resources :archives
|
||||
resources :subscribes
|
||||
resources :subscribes do
|
||||
collection do
|
||||
post :cancel
|
||||
end
|
||||
end
|
||||
get '/unsubscribe' => 'subscribes#index'
|
||||
# photos
|
||||
resources :photos, only: [:create]
|
||||
get '/qrcodes' => 'qrcodes#show'
|
||||
|
|
|
@ -4,14 +4,14 @@ describe SubscribesController do
|
|||
|
||||
describe "POST 'create'" do
|
||||
it "post ok" do
|
||||
post 'create', email: 'a@b'
|
||||
post 'create', email: 'tester@test.com'
|
||||
expect(JSON.parse(response.body)['success']).to be_true
|
||||
expect(Subscribe.all.size).to eq(1)
|
||||
end
|
||||
|
||||
it "post with disabled email" do
|
||||
subscribe = Subscribe.create(email: 'a@b', enable: false)
|
||||
post 'create', email: 'a@b'
|
||||
subscribe = Subscribe.create(email: 'tester@test.com', enable: false)
|
||||
post 'create', email: 'tester@test.com'
|
||||
expect(JSON.parse(response.body)['success']).to be_true
|
||||
expect(subscribe.reload.enable).to be_true
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue