浏览 2310 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (3) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-02-13
所以第一步:安装插件: sudo gem install rmagick ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/ ruby script/plugin install http://sean.treadway.info/svn/plugins/responds_to_parent/ 二。用scaffold 创建一个资源 ruby script/generate scaffold photo *不要忘了修改一下database.yml里面的配置。 三。修改一下migration表: class CreateAssets < ActiveRecord::Migration def self.up create_table :assets do |t| t.column :filename, :string t.column :content_type, :string t.column :size, :integer t.column :width, :integer t.column :height, :integer t.column :parent_id, :integer t.column :thumbnail, :string t.column :created_at, :datetime end end def self.down drop_table :assets end end 四。在model里要运用到这个attachment_fu 插件,要写调用语句: class Asset < ActiveRecord::Base has_attachment :storage => :file_system, :max_size => 1.megabytes, :thumbnails => { :thumb => '80x80>', :tiny => '40x40>' }, :processor => :Rmagick end 五。在index.html里面调用脚本 "prototype", "effects", "application" 也可以在主页里面用: <%= javascript_include_tag :defaults %>|| <%= javascript_include_tag :all%> 六。修改photo/index.html页面 <% form_for(:asset, :url => assets_path, :html => { :multipart => true }) do |f| %> <p> <label for="uploaded_data">Upload a file:</label> <%= f.file_field :uploaded_data %> </p> <p><%= submit_tag "Create" %></p> <% end %> <iframe id='upload_frame' name="upload_frame" style="width:1px;height:1px;border:0px" src="about:blank"></iframe> <ul id="assets"> <% @assets.each do |a|%> <li id="asset"> <%= link_to image_tag(a.public_filename(:tiny)) %><br /> </li> <% end %> </ul> 七。修改一下photo.controller.rb里面的create action def create @asset = Asset.new(params[:asset]) respond_to do |format| if @asset.save flash[:notice] = '图像已经成功上传' format.html { redirect_to (@asset) } format.xml { head :created, :location => asset_url(@asset) } else format.html { render :action => "new" } format.xml { render :xml => @asset.errors.to_xml } end end end [b]这样,在routes.rb文件里设置一下路由就可以rakd db:migrate 运行了。好了,到浏览器里去看看效果吧。嘿嘿嘿。。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-02-18
???why no people has problem??
|
|
返回顶楼 | |
发表时间:2009-02-19
jshmemory 写道 ???why no people has problem??
Only minor problems. It is quite easy to solve them. |
|
返回顶楼 | |