我有一个小的Rails 3.2.1应用程序使用CarrierWave 0.5.8将文件上传到S3(使用Fog)
我希望用户能够选择他们想要下载的一些图像,然后将它们压缩并发送一个拉链.这是我提出的:
def generate_zip
#A collection of Photo objects. The Photo object has a PhotoUploader mounted.
photos = Photo.all
tmp_filename = "#{Rails.root}/tmp/" << Time.now.strftime('%Y-%m-%d-%H%M%S-%N').to_s << ".zip"
zip = Zip::ZipFile.open(tmp_filename, Zip::ZipFile::CREATE)
zip.close
photos.each do |photo|
file_to_add = photo.photo.file
zip = Zip::ZipFile.open(tmp_filename)
zip.add("tmp/", file_to_add.path)
zip.close
end
#do the rest.. like send zip or upload file and e-mail link
end
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为photo.photo.file返回CarrierWave :: Storage :: Fog :: File的实例而不是常规文件.
编辑:这导致的错误:
Errno :: ENOENT:没有这样的文件或目录 - uploads/photos/name.jpg
我也尝试过以下方法:
tmp_filename = "#{Rails.root}/tmp/" << Time.now.strftime('%Y-%m-%d-%H%M%S-%N').to_s << ".zip" …Run Code Online (Sandbox Code Playgroud) 我今天有一个关于Objective-C的问题涉及NSMutableArray.来自.net/c#背景我在处理这些事情时遇到了一些麻烦.
假设我有一个名为"Song"的对象
我的歌有3个属性:
我有一个NSMutableArray或NSArray,它拥有我所有的Song对象.
我将如何尝试"查询"我的阵列以获得仅具有(唯一)艺术家或流派的新阵列.
在.net中你会用DISTINCT子句编写一个简单的LINQ查询,如何在Objective-C中解决这个问题?我猜测谓词,但我很难找到解决方案.
提前致谢.
在我的情况下,我遇到了一些被认为是错误的事情.可能这不是一个错误,而是一个功能;).
这是我的情况:
我用我的内容加载UIScrollView.视图加载后,我的内容的一部分被加载asynchrone.这很好,没有问题.但是,其中一些控件是UITextView控件.一旦我在viewDidLoad之后设置了这些控件的内容(文本属性),我的UIScrollView就会向下滚动到最后设置的UITextView.我想阻止这一点,并希望UIScrollView保持它的顶部滚动位置.
总结:如果我在viewDidLoad方法中设置Text属性,则不会发生滚动.如果我在viewDidLoad方法之后在UITextView上设置Text属性(因为我将数据异步加载),UIScrollView将滚动到最后设置的UITextView.我想阻止这个卷轴.
我该如何实现这一目标?我有一种感觉,这只是一个设置错误的属性,但我似乎无法找到它.
提前致谢.
编辑:
我已经尝试在设置值之前将"scrollEnabled"属性设置为NO,然后设置为YES,但这没有任何效果.当设置UITextView的text属性时,ScrollView仍将滚动.
我正在开发iOS应用程序.它目前仅适用于iOS 4,因为我在几个场合使用以下方法:"UIGraphicsBeginImageContextWithOptions".此方法仅适用于iOS 4,因此我的应用程序当前崩溃/无法在iPhone OS 3上运行.除此方法外,没有理由认为应用程序无法在iPhone OS 3上运行.如何检查看这个方法有没有?我尝试了以下没有成功:
if([self respondsToSelector:@selector(UIGraphicsBeginImageContextWithOptions)]) {
UIGraphicsBeginImageContextWithOptions(targetSize, NO, 0.0); // this will crop
}
else
{
UIGraphicsBeginImageContext(targetSize);
}
Run Code Online (Sandbox Code Playgroud)
我只试过这样的变化:
if([self respondsToSelector:@selector(UIGraphicsBeginImageContextWithOptions:size:opaque:scale:)])
Run Code Online (Sandbox Code Playgroud)
和
if([self respondsToSelector:@selector(UIGraphicsBeginImageContextWithOptions:)])
Run Code Online (Sandbox Code Playgroud)
没有成功.任何帮助,将不胜感激.
我正在尝试为侧面项目创建一个超级简单的JSON Web服务.但是我在将对象转换为JSON时遇到了一些麻烦,有人可以帮帮我吗?
我有以下课程:
class Location
attr_reader :street, :city, :state, :country, :zip, :latitude, :longitude
def initialize(street, city, state, country, zip, latitude, longitude)
@street = street
@city = city
@state = state
@country = country
@zip = zip
@latitude = latitude
@longitude = longitude
end
def to_json
{
'street' => @street,
'city' => @city,
'state' => @state,
'country' => @country,
'zip' => @zip,
'latitude' => Float(@latitude),
'longitude' => Float(@longitude)
}.to_json
end
end
Run Code Online (Sandbox Code Playgroud)
和
class Spot
attr_reader :name, :category, :location, :id
def initialize(id, …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一些CoffeScript函数,在检查表中的复选框时检查表中的所有复选框.
我在CoffeeScript中的功能如下所示:
$("table.tableview th input:checkbox").live 'click', ->
checkedStatus = this.checked
$("table.tableview tbody tr td:first-child input:checkbox").each ->
this.checked = checkedStatus
Run Code Online (Sandbox Code Playgroud)
它非常适合检查所有方框.但是,取消选中它不起作用.编译好的JS看起来像这样:
$("table.tableview th input:checkbox").live('click', function() {
var checkedStatus;
checkedStatus = this.checked;
return $("table.tableview tbody tr td:first-child input:checkbox").each(function() {
return this.checked = checkedStatus;
});
});
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为在第一个设置为false后,函数的返回将为false.但是我不知道如何抑制咖啡脚本的这种默认返回行为.请帮忙.
当我根据Flambino的建议添加"true"时,我得到以下JS
$("table.tableview th input:checkbox").live('click', function() {
var checkedStatus;
checkedStatus = this.checked;
$("table.tableview tbody tr td:first-child input:checkbox").each(function() {
return this.checked = checkedStatus;
});
return true;
});
Run Code Online (Sandbox Code Playgroud)
我可以在函数内部获取return语句的唯一方法是将它一直放在这样:
$("table.tableview tbody tr td:first-child input:checkbox").each ->
this.checked = checkedStatus
true …Run Code Online (Sandbox Code Playgroud) 我有以下2种导轨型号:
class Profile < ActiveRecord::Base
belongs_to :user
has_many :votes, through: :user
default_scope includes(:user)
end
Run Code Online (Sandbox Code Playgroud)
和
class Vote < ActiveRecord::Base
attr_accessible :by, :for
belongs_to :by, class_name: "User"
belongs_to :for, class_name: "User"
validates :by, :for, presence: true
validates_uniqueness_of(:by, scope: :for)
end
Run Code Online (Sandbox Code Playgroud)
我正在尝试在Profile上创建一个"顶部"范围,根据相关用户记录收到的"for"投票数量对Profiles进行排序
用户为用户创建投票."by"列表示投票的用户,"for"栏表示已收到投票的用户.我正在尝试获得获得最多选票的用户的个人资料.
这是我到目前为止所得到的:
scope :top,
select("profile.*, count(votes.id) AS votes_count").
joins(:votes, :user).
order("votes_count DESC")
Run Code Online (Sandbox Code Playgroud)
这不适用于以下错误:
ActiveRecord :: StatementInvalid:PG ::错误:错误:列"votes_count"不存在
它也不考虑"for"列
谁能帮我吗 ?
objective-c ×3
cocoa-touch ×2
ruby ×2
activerecord ×1
amazon-s3 ×1
carrierwave ×1
coffeescript ×1
ios4 ×1
iphone ×1
javascript ×1
json ×1
nsarray ×1
postgresql ×1
sql ×1
uikit ×1
uiscrollview ×1
uitextview ×1
zip ×1