【发布时间】:2013-12-18 17:12:01
【问题描述】:
这里是upload.rb(模型)
class Upload < ActiveRecord::Base
belongs_to :post
has_attached_file :name, :styles => { :medium => ["600x400>",:jpg], :thumb => ["122x122>",:jpg]}, url: "/post_images/post_:post_id/:style/:filename"
def self.image_url
"/post_images/post_:post_id/medium/:filename"
end
end
如何获取上传文件的url。
我的控制器:
def img_upload
@image = Upload.new post_id: post_id, name: params[:Filedata]
if @image.save
render json: Upload.image_url
end
end
谁能帮帮我。
【问题讨论】:
-
在您的视图中还是在您的控制器中?
-
@Justin 我也包含了我的控制器
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 paperclip