这个。。。。。
点进去后逛了一下,然后发现:怎么这么多讨论 android 的,这不是 rubychina 吗。。。?结果发现自己在 diycode 里。。。
if !weather.nil?
session[:current_weather] = 'rain' if weather.include?("雨")
session[:current_weather] = 'snow' if weather.include?("雪")
session[:current_weather] = 'cloud' if weather.include?("云")
end
if !weather.nil? 建议换成 if weather.present?
还会根据不同天气给出不同背景吗?特效很 nice 啊感觉!
blog 的背景是用的什么插件吗
伟大的字幕组团队用的竟是 rails~!顶!
我之前也以为是自己哪设置没对,win 下和 mac 下都丑哭...还晃眼
已买,50 大洋花去...感觉部署那本太贵了,2M 就 30 块,还是 5 折....
#16 楼 @redemption 执行逻辑是一样的,可能有些细小的差别或者什么机制影响的。2 个对象的调用都是通过同一个 patters_controller 的 index 进入 base_model 里的 default 的。不想深究了....一想着 随便加个空格,程序第一次就报错,之后就正常的现象就够恶心了...
#14 楼 @redemption 不是 order 没有调用成功,是调用 order 的主体,以及它主体的主体没有成功,就是第一句 relation = clone,在 micropost 中无法克隆自己,我也不知道为什么。
#11 楼 @redemption 谢谢了。把 clone 换成 self 就可以了。但还是不清楚为啥 Micropost 里不能 clone 自己而 User 可以..
#10 楼 @redemption 在报错的时候输出 model,直接说没有这个变量。。项目在这里。
发现问题好像出在这,这是_where 方法,是 default 方法调用的它
def _where params
relation = clone
case
when params.is_a?(String); return relation
when params.is_a?(Array); return relation
when params.is_a?(Hash)
params = params.map do |field, condition|
condition = case
when condition.is_a?(Hash); condition
when condition.is_a?(Range); { '>=' => condition.begin, '<=' => condition.end }
when condition.is_a?(Array); { 'in' => condition }
else; { '=' => condition }
end
condition.each do |operator, value|
{ %[''] => '', %[""] => '', 'true' => true, 'false' => false, 'nil' => nil, 'null' => nil }.each{|x,y| value = y if value == x }
operator = operator.to_s.downcase
operator = { 'eq' => '=', 'lt' => '<', 'gt' => '>', 'gteq' => '>=', 'lteq' => '<=', 'noteq' => '!=' }[operator] || operator
# operator = { '<' => 'lt', '>' => "gt", '>=' => 'gtep', '<=' => 'lteq', "!=" => 'noteq'}[operator.to_s] || operator
next if 'active' == field
operator = { '=' => 'is', '!=' => 'is not' }[operator] if value === nil
# raise unless field.to_s =~ /^(?:[`'"]?(\w+)[`'"]?\.)?[`'"]?(\w+)[`'"]?$/ && (%w[= > < >= <= != in like is]+['is not']).include?(operator)
if operator == 'like'
relation = relation.where("#{field.to_sym} like ?", "%#{value}%") if value.to_s.present?
elsif ["=", "<", ">", ">=", "<=", "!="].include?(operator)
# relation = relation.where(field.to_sym.send(operator) => value) if value.present?
p field
relation = relation.where("#{field} #{operator} ?", value) if value.to_s.present?
else
relation = relation.where(field.to_sym => value) if value.present?
# end
end
end
end
end
relation || clone
end
在 Micropost 里没有办法 clone 自己,所以报错,但在同样的 user 下就没有问题。。
#7 楼 @redemption 就是两种情况下输出 self,都是 Micropost 对象。唯一区别就是上面提到的
#7 楼 @redemption 问题就在这,当项目随便保存一个空格(不改代码)在 default 的第一句断点里,调试输入一下 self,程序没有任何报错。但断点里如果不输入 self,那么直接 exit,就会报上面的错。
#3 楼 @redemption 可能是之前调试的时候改过没注意...执行主体就是 self,是 self._where,我把原文改过来了
在调用 default 方法前打断点,执行 model.default,两次结果不一样,第一次报错,也就是页面上看到的错,第二次就正常了,为什么会出现这种情况?
def model
name = self.class.name
return if name =~ /ApplicationController$/
@model ||= name.remove(/^Manage|Controller$/).singularize.constantize
end
model.default(params)
Load (1.0ms) SELECT "".* FROM "" ORDER BY "microposts"."created_at" DESC, created_at desc
SQLite3::SQLException: no such table: : SELECT "".* FROM "" ORDER BY "microposts"."created_at" DESC, created_at desc
=> #<#<Class:#<Micropost::ActiveRecord_Relation:0x007f7dccd10050>>:0x3fbee6688028>
[2] pry(#<Manage::MicropostsController>)> model.default(params)
Load (0.4ms) SELECT "microposts".* FROM "microposts" ORDER BY "microposts"."created_at" DESC, created_at desc
=> [#<#<Class:0x007f7dccc85680>:0x007f7dccbfcc68
id: 11,
content: "saddas",
user_id: 18,
created_at: Sat, 30 Apr 2016 14:27:35 UTC +00:00,
updated_at: Sat, 30 Apr 2016 14:27:35 UTC +00:00,
picture: nil>,
#<#<Class:0x007f7dccc85680>:0x007f7dccbfcb00
id: 10,
content: "dasdsa",
user_id: 18,
created_at: Sat, 30 Apr 2016 13:55:33 UTC +00:00,
updated_at: Sat, 30 Apr 2016 13:55:33 UTC +00:00,
picture: nil>]
为啥 11M 的 REpec 才 15,4M 的部署之道要贵 1 倍啊.....
是没有问题的,注意是不是翻译的内容有空格 比如 User: 狗 蛋
有空格得放字符串里,楼主试试
酷!
氛围感觉超和谐!
上家公司就是生鲜 o2o...但现在马上面临毕业没太多时间,帮顶了!
搞清楚 rails 的继承关系吧,顺着约束走自然就明白该什么时候用了。
#10 楼 @u1453357893 后台挺简单的,就只有一句话,update 一下大概是文件名到对应字段。回复里的代码是模拟前端提交文件,测试 api 用的。
之前项目做的是前后端分离,有点久了,前端是别人写的,所以只知道后台部分。
记得之前做过类似的。大概逻辑是,
后台:写一个 update 操作,更新上传的文件名。 安卓那边直接提交表单,表单里需要传的什么参数,就参考用辅助方法生成的表单传的参数吧,本质上都一样。楼主参考下面这段模拟吧
when 'http'
file = "./u.png"
header = {"Content-Type" => "multipart/form-data, boundary=#{BOUNDARY}"}
post_body = []
post_body << "--#{BOUNDARY}\r\n"
post_body << "Content-Disposition: form-data; name=\"user[photo]\"; filename=\"#{File.basename(file)}\"\r\n"
post_body << "Content-Type: image/png\r\n\r\n"
post_body << File.read(file)
post_body << "\r\n\r\n--#{BOUNDARY}--\r\n"
uri = URI.parse("#{ROOT}/api/userphoto_update?client_uuid=#{CUUID}&latitude=#{LATITUDE}&longitude=#{LONGITUDE}")
http = Net::HTTP.new(uri.host, uri.port)
req = Net::HTTP::Put.new(uri.request_uri, header)
req.body = post_body.join
req.basic_auth("#{LOGINNAME}", "#{PASSWORD}")
r = http.request(req)
if r.code.to_i == 200
$messages = $messages + "\n" if $messages != ""
$messages = $messages + "#{api_type} OK - #{r.code}: #{r.message}"
else
$messages = $messages + "\n" if $messages != ""
$messages = $messages + "#{api_type} WARNING - #{r.code}: #{r.message}"
end
end
这大概是半年前的项目里的一个小功能了,当时是需要给公众号里的页面提供一个用户上传头像还是照片的功能。
唉,这个 zf 最近很多行为让大家越来越寒心,也不奇怪了。
#2 楼 @yunfei1982 国内的工作,都希望远程,国外的工作,都希望赴 XX 工作 = =
#7 楼 @hemengzhi88 哈哈,严重同意 #8 楼 @frankking 豆瓣找同城活动多露面吧。喜欢萝莉就去动漫同城圈,喜欢安静的就去读书沙龙同城,etc...合适就下手。