Admin subscribe manage
This commit is contained in:
parent
218548c3b4
commit
f543fad37d
|
@ -0,0 +1,3 @@
|
|||
.admin-subscribes-field {
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@ class Admin::PostsController < ApplicationController
|
|||
end
|
||||
|
||||
def index
|
||||
@posts = Post.order(created_at: :desc).page(params[:page])
|
||||
@posts = Post.order(created_at: :desc).page(params[:page]).per(25)
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
class Admin::SubscribesController < ApplicationController
|
||||
layout 'layouts/admin'
|
||||
before_action :authericate_user!
|
||||
|
||||
def index
|
||||
@subscribes = Subscribe.all.order(created_at: :desc).page(params[:page]).per(25)
|
||||
end
|
||||
|
||||
def enable
|
||||
@subscribe = Subscribe.find(params[:id])
|
||||
|
||||
@subscribe.enable = true
|
||||
@subscribe.save!
|
||||
|
||||
redirect_to admin_subscribes_path, notice: "#{@subscribe.email} is enabled!"
|
||||
end
|
||||
|
||||
def disable
|
||||
@subscribe = Subscribe.find(params[:id])
|
||||
|
||||
@subscribe.enable = false
|
||||
@subscribe.save!
|
||||
|
||||
redirect_to admin_subscribes_path, notice: "#{@subscribe.email} is disabled!"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
.row.admin-subscribes-field
|
||||
.small-12.columns
|
||||
h3.blog-title #{t('admin.subscribes') }
|
||||
table width="100%"
|
||||
thead
|
||||
tr
|
||||
th #{t('admin.subscribes_head.email')}
|
||||
th #{t('admin.subscribes_head.enable')}
|
||||
th #{t('admin.subscribes_head.created_at')}
|
||||
th #{t('admin.subscribes_head.operation')}
|
||||
tbody
|
||||
- @subscribes.each do |subscribe|
|
||||
tr
|
||||
td
|
||||
= mail_to subscribe.email
|
||||
td
|
||||
= subscribe.enable
|
||||
td
|
||||
= format_time(subscribe.created_at)
|
||||
td
|
||||
- if subscribe.enable
|
||||
= link_to t('admin.subscribes_head.op.disable'), disable_admin_subscribe_path(subscribe), method: 'POST', data: { confirm: 'Confirm?' }
|
||||
- else
|
||||
= link_to t('admin.subscribes_head.op.enable'), enable_admin_subscribe_path(subscribe), method: 'POST', data: { confirm: 'Confirm?' }
|
||||
== paginate @subscribes
|
|
@ -20,6 +20,8 @@ html
|
|||
= link_to t('admin.new_post'), new_admin_post_path
|
||||
li
|
||||
= link_to t('admin.posts'), admin_posts_path
|
||||
li
|
||||
= link_to t('admin.subscribes'), admin_subscribes_path
|
||||
.top-bar-right
|
||||
ul.menu
|
||||
li
|
||||
|
|
|
@ -77,6 +77,16 @@ en:
|
|||
reply: 'Reply'
|
||||
destroy: 'Destroy'
|
||||
|
||||
subscribes: 'Manage Subscribes'
|
||||
subscribes_head:
|
||||
email: 'Email'
|
||||
enable: 'Enable Flag'
|
||||
created_at: 'Created at'
|
||||
operation: 'Operation'
|
||||
op:
|
||||
enable: 'Enable'
|
||||
disable: 'Disable'
|
||||
|
||||
back: 'Back to Home'
|
||||
logout: 'Logout'
|
||||
dashboard:
|
||||
|
|
|
@ -77,6 +77,16 @@ zh-CN:
|
|||
reply: '回复'
|
||||
destroy: '删除'
|
||||
|
||||
subscribes: '订阅管理'
|
||||
subscribes_head:
|
||||
email: '邮箱'
|
||||
enable: '是否启用'
|
||||
created_at: '创建时间'
|
||||
operation: '操作'
|
||||
op:
|
||||
enable: '启用'
|
||||
disable: '禁用'
|
||||
|
||||
back: '返回首页'
|
||||
logout: '退出'
|
||||
dashboard:
|
||||
|
|
|
@ -29,6 +29,12 @@ WBlog::Application.routes.draw do
|
|||
resources :comments
|
||||
end
|
||||
resources :sessions, :only=>[:new, :create, :destroy]
|
||||
resources :subscribes, only: [:index] do
|
||||
member do
|
||||
post :enable
|
||||
post :disable
|
||||
end
|
||||
end
|
||||
root 'dashboard#index'
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe Admin::SubscribesController, :type => :controller do
|
||||
|
||||
before do
|
||||
session[:login] = true
|
||||
end
|
||||
|
||||
describe "GET index" do
|
||||
it "returns http success" do
|
||||
get :index
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST enable" do
|
||||
it "returns http success" do
|
||||
subscribe = create(:subscribe)
|
||||
post :enable, id: subscribe.id
|
||||
expect(subscribe.reload.enable).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST disable" do
|
||||
it "returns http success" do
|
||||
subscribe = create(:subscribe, enable: true)
|
||||
post :disable, id: subscribe.id
|
||||
expect(subscribe.reload.enable).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue