- 浏览: 187771 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (83)
- J2EE/Core Java (24)
- J2EE/Portal (2)
- J2EE/UI (4)
- J2EE/ATG (1)
- J2EE/Report (1)
- J2EE/Web Service/Rest API (2)
- Design Pattern (2)
- Arithmetic (4)
- Linux (12)
- Ruby&Rails (17)
- Database (5)
- J2EE/Payment (1)
- J2EE/JVM (1)
- Encryption/Decryption (3)
- J2EE/Multi Threading (4)
- SQL (1)
- https://community.teamviewer.com/t5/Knowledge-Base/Where-can-I-download-older-TeamViewer-versions-nbsp/ta-p/7729 (0)
最新评论
1. 创建一个保存文件的表,然后rake db:migrate同步到数据库
2. 创建UploadController
3. 文件上传初始页面get.html.erb
4. 上传后的从数据库中读取图片并显示图片的页面show.html.erb
5. 访问http://localhost:3000/upload/get
class CreatePictures < ActiveRecord::Migration def self.up create_table :pictures do |t| t.string :comment t.string :name t.string :content_type # If using MySQL, blobs default to 64k, so we have to give # an explicit size to extend them t.binary :data, :limit => 1.megabyte end end def self.down drop_table :pictures end end
2. 创建UploadController
class UploadController < ApplicationController def get @picture = Picture.new end def save @picture = Picture.new(params[:picture]) if @picture.save redirect_to(:action => 'show', :id => @picture.id) else render(:action => :get) end end def show @picture = Picture.find(params[:id]) end def picture @picture = Picture.find(params[:id]) send_data(@picture.data, :filename => @picture.name, :type => @picture.content_type, :disposition => "inline") end end
3. 文件上传初始页面get.html.erb
<%= error_messages_for("picture" ) %> <% form_for(:picture, :url => {:action => 'save'}, :html => { :multipart => true }) do |form| %> Comment: <%= form.text_field("comment" ) %><br/> Upload your picture: <%= form.file_field("uploaded_picture" ) %><br/> <%= submit_tag("Upload file" ) %> <% end %>
4. 上传后的从数据库中读取图片并显示图片的页面show.html.erb
<h3><%= @picture.comment %></h3> <img src="<%= url_for(:action => 'picture', :id => @picture.id) %>"/>
5. 访问http://localhost:3000/upload/get
发表评论
-
Eigenclass in Ruby
2016-08-02 17:50 484obj = Object.new def obj.sin ... -
First DSL With Ruby
2016-08-02 16:23 508test_event.rb event "an ... -
Ruby Version of C# using keyword
2016-08-02 11:51 438class Resource1 def disp ... -
Rails4 集成测试微信公众号API
2016-01-17 20:34 1064这是一个简单集成微信api的的例子,使用这个Gem:https ... -
localtunnelling绑定本地Web应用到公网地址
2016-01-17 20:14 536引用Localtunnel will assign you a ... -
WordPress 风格开源博客 (响应式布局)
2015-08-09 23:42 655Rails4个人开源小博客 介绍: https://ruby ... -
Rails实现markdown和代码高亮
2015-08-07 11:47 739安装GEM Markdown是时下很流行的一种标记语言。 ... -
TextMate常见快捷键
2015-08-07 11:42 2265cmd + option + L 显示行号 cmd ... -
Rails插件twitter-bootstrap-rails
2015-08-07 11:40 542github完整项目 https://github.com/ ... -
Heroku个人博客
2015-02-10 12:04 6http://wilsoncai.herokuapp.com/ ... -
Rails 4 Quick Start
2014-12-13 10:47 0set rails gem proxy from Taobao ... -
Ruby1.8.7 安装和使用selenium
2013-06-21 17:54 1059引用Selenium可以用来模拟浏览器页面点击,可以用来做页面 ... -
Rails2.2.2之国际化
2013-01-27 23:52 8481. 新建国际化配置文件config\initializers ... -
Rails2.2.2之发送邮件
2013-01-27 23:32 7221. config\environment.rb中添加smtp ... -
Rails2.2.2之will_paginate分页
2013-01-27 23:04 1177引用分页是web开发中常见的问题,基本解决思路是每次查询当页的 ... -
Ruby 代码块
2013-01-14 18:27 796引用Ruby代码块可以通过yield方法传递给被调用的方法 1 ... -
Ruby发送邮件(163邮箱)
2011-10-25 17:27 7077Ruby1.8.6发送163邮件到gmail require ... -
Rails2.2.2之windows环境搭建
2010-07-20 15:46 3709引用如果gem速度慢 使用代理安装rails 引用gem in ...
相关推荐
rails 2.2.2 API 英文的
NULL 博文链接:https://caerun.iteye.com/blog/717015
RoR学习的最好参考手册,api参考手册,功能详细,论述清晰,是学习rails框架的不可缺少的手册
NULL 博文链接:https://0512szren.iteye.com/blog/712709
rails-2.2.2.zip 安装包
NULL 博文链接:https://0512szren.iteye.com/blog/712318
jquery-fileupload-rails, 用于 Rails的jQuery文件上传集成 Rails 文件上传jQuery-File-Plugin 是一个文件上传插件,由的Tschan 。 jQuery文件上传功能多文件选择。drag&拖放支持。进度栏和jQuery预览图像。 支持...
可实现多文件的同时上传,控制文件的格式,数量,同时兼容IE6,7,firefox,易于扩展
NULL 博文链接:https://mylir.iteye.com/blog/800734
rails 分页插件will_paginate 2.2.2
《应用Rails进行敏捷Web开发》中文第三版,找了很久才找到,介绍的是rails2.2.2
NULL 博文链接:https://dendrobium.iteye.com/blog/305938
css和图片 博文链接:https://hideto.iteye.com/blog/197517
《Rails之道》按照Rails的各个子系统进行组织编排,分别介绍了Rails的环境、初始过程、配置和日志记录,Rails的分配器、控制器、页面生成和路由,REST、资源和Rails,ActiveRecord的基础、关联、验证和高级技巧,...
NULL 博文链接:https://zyn-zyn.iteye.com/blog/1163143
Web开发敏捷之道—应用Rails进行Web开发,第3版 书中的代码是基于ruby 1.8.6和rails 2.2.2
Paperclip 是 Rails 框架的一个插件,用于扩展 ActiveRecord 以支持简单的文件附件的功能。 标签:Paperclip