From 803f4a3eaf91851afbaec09cbe849a6ca940e0bd Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 10 Mar 2015 14:41:36 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E9=83=A8=E5=88=86=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=A0=B9=E6=8D=AEapptoken=E5=8F=82=E6=95=B0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD=E6=B7=BB=E5=8A=A0token?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E8=BF=87=E6=9C=9F=E5=88=A4=E6=96=AD=E3=80=82?= =?UTF-8?q?2=E3=80=81=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E6=96=B0=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 23 ++++++++++++++++++++++- app/controllers/application_controller.rb | 3 +++ app/models/phone_app_version.rb | 2 ++ app/views/admin/mobile_version.html.erb | 2 +- config/locales/zh.yml | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index c77ebe704..413ed9692 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -337,7 +337,28 @@ class AdminController < ApplicationController end def create_version - + @versions = PhoneAppVersion.reorder('created_at desc') + @new_version = PhoneAppVersion.new + @new_version.version = params[:version] + @new_version.description = params[:description] + if @new_version.save + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + redirect_to mobile_version_url + } + format.api { render_api_ok } + end + else + respond_to do |format| + flash.now[:error] = "#{l :label_version_create_fail}: #{@new_version.errors.full_messages[0]}" + #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}" + format.html { + render :action => 'mobile_version' + } + format.api { render_validation_errors(@new_version) } + end + end end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c26ec07e..47251cf85 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -181,6 +181,9 @@ class ApplicationController < ActionController::Base #从手机端传来apptoken则将当前登陆用户变为对应的用户 if params[:apptoken] token = ApiKey.where(access_token: params[:apptoken]).first + if token.expired? + return + end if token && !token.expired? @current_user = User.find(token.user_id) end diff --git a/app/models/phone_app_version.rb b/app/models/phone_app_version.rb index abf4c54e3..4dc1503c9 100644 --- a/app/models/phone_app_version.rb +++ b/app/models/phone_app_version.rb @@ -1,3 +1,5 @@ class PhoneAppVersion < ActiveRecord::Base attr_accessible :description, :version + validates_presence_of :description, :version + validates_uniqueness_of :version end diff --git a/app/views/admin/mobile_version.html.erb b/app/views/admin/mobile_version.html.erb index 5ea340245..0d38b449a 100644 --- a/app/views/admin/mobile_version.html.erb +++ b/app/views/admin/mobile_version.html.erb @@ -1,7 +1,7 @@

<%= l(:label_mobile_version) %>

发布新版本
- <%= form_tag(:controller => 'admin', :action => 'create_version') do %> + <%= form_tag({:controller => 'admin', :action => 'create_version'},{:id => 'new_version',:style=>'display:none'}) do %>

<%= text_field_tag 'version', params[:version],:value => @new_version.version, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index e2b5ea53a..26dc11508 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1979,6 +1979,7 @@ zh: label_forum_update_succ: 贴吧更新成功 label_forum_update_fail: 贴吧更新失败 label_first_page_create_fail: 首页定制失败 + label_version_create_fail: 版本发布失败 label_forum_edit: 编辑讨论区 label_memo_create: 发布 label_memo_new: 新建帖子