首页定制添加剂修改图片大小功能

This commit is contained in:
z9hang 2014-07-25 16:05:33 +08:00
parent 2c08f39001
commit 97531960da
13 changed files with 80 additions and 11 deletions

View File

@ -150,6 +150,8 @@ class AdminController < ApplicationController
@first_page.web_title = params[:web_title]
@first_page.description = params[:first_page][:description]
#@first_page.title = params[:title]
@first_page.image_width = params[:image_width]
@first_page.image_height = params[:image_height]
@first_page.sort_type = params[:sort_type]
if @first_page.save
respond_to do |format|
@ -183,6 +185,8 @@ class AdminController < ApplicationController
@first_page.web_title = params[:web_title]
@course_page.web_title = params[:web_title]
@course_page.title = params[:course_title]
@course_page.image_width = params[:image_width]
@course_page.image_height = params[:image_height]
@course_page.description = params[:course_description]
if @first_page.save && @course_page.save
respond_to do |format|
@ -219,6 +223,8 @@ class AdminController < ApplicationController
@first_page.web_title = params[:web_title]
@contest_page.web_title = params[:web_title]
@contest_page.title = params[:contest_title]
@contest_page.image_width = params[:image_width]
@contest_page.image_height = params[:image_height]
@contest_page.description = params[:contest_description]
@notification.title = params[:contest_notification_title]
@notification.content = params[:contest_notification][:content]

View File

@ -2,5 +2,7 @@ class FirstPage < ActiveRecord::Base
attr_accessible :description, :title, :web_title,:page_type,:sort_type
validates_presence_of :web_title, :title, :description,:page_type
validates_length_of :web_title,:title, maximum: 30
validates_inclusion_of :image_width,:in => 50..120, :message => l(:image_width_error_message)
validates_inclusion_of :image_height,:in => 50..80, :message => l(:image_height_error_message)
#validates_length_of :description, maximum: 100
end

View File

@ -20,6 +20,14 @@
<div style="margin-left: 82px;" id="avatar">
<%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@contest_page} %>
</div>
<p style="margin-left:60px;padding-right: 20px;">
<label for='image_width' style="vertical-align: top">&nbsp;&nbsp;&nbsp;<%= l(:label_image_width)%>:</label>
<%= text_field_tag 'image_width', params[:label_image_width],:value => @contest_page.image_width,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
</p>
<p style="margin-left:60px;padding-right: 20px;">
<label for='image_height' style="vertical-align: top">&nbsp;&nbsp;&nbsp;<%= l(:label_imgae_height)%>:</label>
<%= text_field_tag 'image_height', params[:label_imgae_height], :value => @contest_page.image_height,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
</p>
<p style="margin-left:60px;padding-right: 20px;">
<label for='contest_title'>&nbsp;&nbsp;&nbsp;<%= l(:label_site_title) %>:</label>
<%= text_field_tag 'contest_title', params[:label_site_title], :value => @contest_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>

View File

@ -19,6 +19,14 @@
<div style="margin-left: 82px;" id="avatar">
<%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@course_page} %>
</div>
<p style="margin-left:60px;padding-right: 20px;">
<label for='image_width' style="vertical-align: top">&nbsp;&nbsp;&nbsp;<%= l(:label_image_width)%>:</label>
<%= text_field_tag 'image_width', params[:label_image_width],:value => @course_page.image_width,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
</p>
<p style="margin-left:60px;padding-right: 20px;">
<label for='image_height' style="vertical-align: top">&nbsp;&nbsp;&nbsp;<%= l(:label_imgae_height)%>:</label>
<%= text_field_tag 'image_height', params[:label_imgae_height], :value => @course_page.image_height,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
</p>
<p style="margin-left:60px;padding-right: 20px;">
<label for='course_title'>&nbsp;&nbsp;&nbsp;<%= l(:label_site_title) %>:</label>
<%= text_field_tag 'course_title', params[:label_site_title], :value => @course_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>

View File

@ -19,7 +19,14 @@
<div style="margin-left: 82px;" id="avatar">
<%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@first_page} %>
</div>
<p style="margin-left:60px;padding-right: 20px;">
<label for='image_width' style="vertical-align: top">&nbsp;&nbsp;&nbsp;<%= l(:label_image_width)%>:</label>
<%= text_field_tag 'image_width', params[:label_image_width],:value => @first_page.image_width,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
</p>
<p style="margin-left:60px;padding-right: 20px;">
<label for='image_height' style="vertical-align: top">&nbsp;&nbsp;&nbsp;<%= l(:label_imgae_height)%>:</label>
<%= text_field_tag 'image_height', params[:label_imgae_height], :value => @first_page.image_height,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>
</p>
<!-- <p style="margin-left:60px;padding-right: 20px;">
<label for='title'>&nbsp;&nbsp;&nbsp;<#%= l(:label_site_title) %>:</label>
<#%= text_field_tag 'title', params[:label_site_title], :value => @first_page.title,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %>

View File

@ -121,11 +121,11 @@
</div>
<div class="main-content-bar" id="main-content-bar">
<!--文字-->
<div style="float: left">
<div style="float: left;padding-left:15px;">
<% if get_avatar?(@contest_page) %>
<%= image_tag(url_to_avatar(@contest_page), size: "75x75") %>
<%= image_tag(url_to_avatar(@contest_page), width:@contest_page.image_width,height: @contest_page.image_height) %>
<% else %>
<%= image_tag '/images/transparent.png', size: "75x75" %>
<%= image_tag '/images/transparent.png', width:@contest_page.image_width,height: @contest_page.image_height %>
<% end %>
</div>
<div class="welcome_left" id="welcome_left">

View File

@ -37,8 +37,8 @@
<div class="weixin-content">微信扫码</div>
</div>
<div class="main-content-bar" id="main-content-bar">
<div style="float: left">
<%= image_tag(@logoLink, size: '75x75') %>
<div style="float: left;padding-left:15px">
<%= image_tag(@logoLink, width:@course_page.image_width,height: @course_page.image_height) %>
</div>
<div class="course welcome_left" id="welcome_left">

View File

@ -37,9 +37,9 @@
<div style="float: left;padding-left:15px ">
<!-- <#%= image_tag(get_project_avatar(@first_page), size: "75x75") %> -->
<% if get_avatar?(@first_page) %>
<%= image_tag(url_to_avatar(@first_page), size: "107x63") %>
<%= image_tag(url_to_avatar(@first_page), width:@first_page.image_width,height: @first_page.image_height) %>
<% else %>
<%= image_tag '/images/transparent.png', size: "107x63" %>
<%= image_tag '/images/transparent.png', width:@first_page.image_width,height: @first_page.image_height %>
<% end %>
</div>

View File

@ -572,6 +572,10 @@ zh:
label_site_title: 网站标题
label_site_description: 网站简介
label_site_image: 简介图片
label_image_width: 图片宽度
label_imgae_height: 图片高度
image_width_error_message: 图片宽度只能是50至120之间的整数
image_height_error_message: 图片高度只能是50至80之间的整数
label_sort_type: 热门项目排序方式
label_contest_notification_title: 竞赛通知标题
label_contest_notification_content: 竞赛通知内容

View File

@ -0,0 +1,6 @@
class AddColumn < ActiveRecord::Migration
def change
add_column("first_pages","image_width",:integer,default: 107)
add_column("first_pages","image_height",:integer,default: 63)
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140725013735) do
ActiveRecord::Schema.define(:version => 20140725062302) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -423,6 +423,8 @@ ActiveRecord::Schema.define(:version => 20140725013735) do
t.datetime "updated_at", :null => false
t.string "page_type"
t.integer "sort_type"
t.integer "image_width", :default => 107
t.integer "image_height", :default => 63
end
create_table "forums", :force => true do |t|

26
lib/tasks/first_page.rake Normal file
View File

@ -0,0 +1,26 @@
# -*coding:utf-8 -*-
desc "First Page Initialize"
task :first_page do
puts "first_page sync."
end
namespace :first_page do
desc "initialize first page"
task :initialize => :environment do
first_page = FirstPage.where("page_type = 'project'").first
first_page.description = "<div style='margin-top: 3px;'><span style='font-weight: bold; font-size: 18px; color: #e8770d;display:inline-block; margin-top: 5px;'>micROS多态智能集群机器人操作系统 </span><br />
<span style='font-weight:bold; font-size:18px;color:#15bccf; display:inline-block;margin-top:5px;''> </span></div>"
first_page.image_width = 107;
first_page.image_height = 63;
course_page = FirstPage.where("page_type = 'course'").first
course_page.image_width = 75
course_page.image_height = 75
contest_page = FirstPage.where("page_type = 'contest'").first
contest_page.image_width = 75
contest_page.image_height = 75
first_page.save
course_page.save
contest_page.save
puts "initialized Successfully"
end
end