Class: EricWeixin::Cms::Weixin::MediaResourcesController
- Inherits:
-
BaseController
- Object
- BaseController
- EricWeixin::Cms::Weixin::MediaResourcesController
- Defined in:
- app/controllers/eric_weixin/cms/weixin/media_resources_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/eric_weixin/cms/weixin/media_resources_controller.rb', line 14 def create begin p = params.require(:resource).permit(:tags, :category_name, :public_account_id) params.permit :pic if p[:category_name] == 'pic_in_article' EricWeixin::MediaResource.save_pic_in_article p, params[:pic] flash[:success] = '创建成功' redirect_to action: :new return else p[:type] = p[:category_name] EricWeixin::MediaResource.save_media p, params[:pic] flash[:success] = '创建成功' redirect_to action: :new return end rescue Exception=> e dispose_exception e flash[:alert] = get_notice_str redirect_to action: :new, session_content_id: set_session_content end end |
#destroy ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/eric_weixin/cms/weixin/media_resources_controller.rb', line 56 def destroy begin media_resource = ::EricWeixin::MediaResource.find_by_id(params[:id]) media_resource.delete_self flash[:success] = '删除成功' redirect_to action: :index rescue Exception=>e dispose_exception e flash[:alert] = get_notice_str redirect_to action: :index end end |
#edit ⇒ Object
38 39 40 |
# File 'app/controllers/eric_weixin/cms/weixin/media_resources_controller.rb', line 38 def edit @media_resource = ::EricWeixin::MediaResource.find_by_id(params[:id]) end |
#index ⇒ Object
3 4 5 6 7 8 |
# File 'app/controllers/eric_weixin/cms/weixin/media_resources_controller.rb', line 3 def index @media_resources = ::EricWeixin::MediaResource.all.order(:id) @media_resources = @media_resources.where("tags like ?", "%#{params[:tag]}%") unless params[:tag].blank? @media_resources = @media_resources.where(category_name: params[:category_name]) unless params[:category_name].blank? @media_resources = @media_resources.paginate(per_page: params[:per_page]||10, page: params[:page]||1) end |
#new ⇒ Object
10 11 12 |
# File 'app/controllers/eric_weixin/cms/weixin/media_resources_controller.rb', line 10 def new @media_resource = ::EricWeixin::MediaResource.new end |
#update ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/eric_weixin/cms/weixin/media_resources_controller.rb', line 42 def update begin media_resource = ::EricWeixin::MediaResource.find_by_id(params[:id]) = params.require(:resource).permit(:tags)[:tags] media_resource.update! tags: unless .blank? flash[:success] = "更新标签成功。" redirect_to action: :index rescue Exception=>e dispose_exception e flash[:alert] = get_notice_str redirect_to "/eric_weixin/cms/weixin/media_resources/#{params[:id]}/edit?session_content_id=#{set_session_content}" end end |