Class: EricWeixin::Cms::Weixin::MediaArticlesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/eric_weixin/cms/weixin/media_articles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/eric_weixin/cms/weixin/media_articles_controller.rb', line 26

def create
  begin
    EricWeixin::MediaArticle.create_media_article media_article_params
    flash[:success] = '微信文章创建成功,再来一篇吧!'
    redirect_to action: :new
  rescue Exception=> e
    dispose_exception e
    flash[:alert] = get_notice_str
    redirect_to action: :new, session_content_id: set_session_content
  end
end

#editObject



38
39
40
41
42
43
# File 'app/controllers/eric_weixin/cms/weixin/media_articles_controller.rb', line 38

def edit
  @media_article = ::EricWeixin::MediaArticle.find_by_id(params[:id])
  @current_page = 1
  @pics = available_pics
  @total_page = (@pics.count/perpage) +1
end

#indexObject



4
5
6
7
8
# File 'app/controllers/eric_weixin/cms/weixin/media_articles_controller.rb', line 4

def index
  @media_articles = ::EricWeixin::MediaArticle.all.order(:id)
  @media_articles = @media_articles.where("title like ?", "%#{params[:title]}%") unless params[:title].blank?
  @media_articles = @media_articles.paginate(per_page: params[:per_page]||10, page: params[:page]||1)
end

#newObject



10
11
12
13
14
15
16
# File 'app/controllers/eric_weixin/cms/weixin/media_articles_controller.rb', line 10

def new
  @media_article = ::EricWeixin::MediaArticle.new
  @current_page = 1
  @pics = available_pics
  @total_page = (@pics.count/perpage) +1
  @pics = @pics.paginate(per_page: perpage, page: 1)
end

#select_picObject



18
19
20
21
22
23
24
# File 'app/controllers/eric_weixin/cms/weixin/media_articles_controller.rb', line 18

def select_pic
  @pics = available_pics
  @total_page = (@pics.count/perpage) +1
  @pics = @pics.paginate(per_page: perpage, page: params[:target_page].to_i)
  @current_page = params[:target_page].to_i
  render partial: 'select_pic'
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/eric_weixin/cms/weixin/media_articles_controller.rb', line 45

def update
  begin
    media_article = EricWeixin::MediaArticle.find_by_id(params[:id])
    media_article.update_media_article media_article_params
    flash[:success] = '微信文章更新成功!'
    redirect_to action: :index
  rescue Exception=>e
    dispose_exception e
    flash[:alert] = get_notice_str
    redirect_to "/eric_weixin/cms/weixin/media_articles/#{params[:id]}/edit?session_content_id=#{set_session_content}"
  end
end