Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

pictures uploader

  • Loading branch information...
commit 16c968829c3d3fc303e4153846b7bd332096e412 1 parent 703a515
@sunny0425 sunny0425 authored
View
8 app/controllers/pictures_controller.rb
@@ -12,11 +12,13 @@ def create
redirect_to new_picture_path and return
end
- picture = Picture.create_picture(
- :filedata => params[:filedata],
+ picture = Picture.new(
+ :image => params[:filedata],
:user_id => current_user.id,
- :desc => params[:desc].strip
+ :desc => params[:desc].strip,
+ :usage => Picture::FOR_PLANTS
)
+ picture.save
unless params[:plant_zh_name].blank?
n = params[:plant_zh_name]
View
11 app/models/picture.rb
@@ -23,4 +23,15 @@ def self.create_picture(filedata,usage=0)
return picture
end
+ def plant_name
+ plant = self.plant
+ if plant.blank?
+ return "待鉴定"
+ elsif plant.zh_name.blank?
+ return "未知"
+ else
+ return plant.zh_name
+ end
+ end
+
end
View
6 app/uploaders/image_uploader.rb
@@ -40,6 +40,12 @@ def filename
process :resize_to_fill => [240, 240]
end
+ version :page_size do
+ process :resize_to_fit => [480, 480]
+ end
+
+ version :original
+
# Add a white list of extensions which are allowed to be uploaded.
View
8 app/views/home/index.haml
@@ -2,13 +2,11 @@
%ul.p-lists
- @pictures.each do |p|
- plant = p.plant
+
%li
%a{:href => picture_path(p.id)}
.p-top
.class
- - if plant.zh_name.blank?
- .name 待鉴定
- - else
- .name #{plant.zh_name}
+ .name= p.plant_name
- = image_tag(p.image.url(:medium), :alt => plant.zh_name)
+ = image_tag(p.image.url(:medium), :alt => p.plant_name)
View
2  app/views/layouts/index.haml
@@ -29,7 +29,7 @@
%header
.topbar
.function-menu
- = link_to "做笔记", new_plant_path
+ = link_to "做笔记", new_picture_path
%a#search-link{:href => "javascript:void(0);"} 搜植物
/ search beginning
#search
View
19 app/views/pictures/show.haml
@@ -1,18 +1,14 @@
.title
- - if @plant.zh_name.blank?
- %b 未知
- - else
- %b= @plant.zh_name
-
- - if @plant.english_name.blank?
+ %b= @picture.plant_name
+ - if @plant.blank? || @plant.english_name.blank?
- else
= @plant.english_name
- - if @plant.latin_name.blank?
+ - if @plant.blank? || @plant.latin_name.blank?
- else
|
= @plant.latin_name
.plant
- = link_to image_tag(@picture.image.url, :alt => "@plant.zh_name"), "#"
+ = link_to image_tag(@picture.image.url(:page_size), :alt => "@plant.zh_name"), "#"
.slide-nav
.left-nav
.right-nav
@@ -44,14 +40,17 @@
= link_to @user.name, @user.link
2012-1-22 LX5 于上海
%div
- -#= @picture.desc
+ = @picture.desc
%article
%p
-# if @plant.descript.blank?
暂无介绍噢。
-# else
-#= @plant.descript
- = link_to "[编辑]", edit_plant_path(@plant)
+ - if @plant.blank?
+ = link_to "[编辑]", new_plant_path
+ - else
+ = link_to "[编辑]", edit_plant_path(@plant)
%h3.comment-title 评论
%ul.comments
= render 'plants/comm'
Please sign in to comment.
Something went wrong with that request. Please try again.