在我自己动手并开始拔出字典之前,有没有人知道rubygem来生成适合app键的令人难忘的名字.我需要一些可说明的东西,以便我可以为用户提供唯一的电子邮件地址来提交内容.我喜欢Heroku的命名为它的应用程序作为一个例子.
floating-sky-58
simple-fog-45
Run Code Online (Sandbox Code Playgroud) 我不确定我是否应该以这种方式更新记录,或者我是否遗漏了某些东西.
我有一个包含5列(不包括时间戳和id)的表,其中3列是不同的,2表将更新.我将找到或创建的3个不同的是room_id,date和source.另外2个是可用的价格和点数(这些每小时,每天等变化)
我的问题是,如果我首先找到或创建记录,然后更新(或创建)价格和点数,或者我可以一次完成所有操作吗?你现在可以看到我正在做的两种方式,我不确定它是否真的在做我期待的事情.
另外,像这样做find_and_create_by有什么缺点吗?
谢谢
private
def self.parse_data(params,data)
data.beds.each do |bed|
room = Room.find_or_create_room(bed.title, params[:id])
#find clones somehow
#puts bed.nights.first.price
bed.nights.each_with_index do |night,index|
available = Available.find_or_create_by_room_id_and_bookdate_and_source(
:room_id => room.id,
:bookdate => (params[:date].to_date)+index,
:source => data.class.to_s#,
#:price => night.price
)
#available.price = night.price
#available.spots = night.spots
#available.save
end
end
Run Code Online (Sandbox Code Playgroud) 我有Xcode 4.1预览5工作正常,但决定通过App商店升级到最终的xcode 4.1.我首先卸载了Xcode ...
sudo /Developer/Library/uninstall-devtools –mode=all
Run Code Online (Sandbox Code Playgroud)
然后通过应用商店安装Xcode并重新启动.
我也完全删除了RVM,但是......现在每当我尝试安装Ruby版本时它都会失败.在错误文件中我得到这个:
[2011-07-27 18:29:25] ./configure --prefix="/Users/holden/.rvm/usr"
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... config/install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... no
checking for gcc... /usr/bin/gcc-4.2
checking whether the C compiler works... no
configure: error: in `/Users/holden/.rvm/src/yaml-0.1.4':
configure: error: C compiler cannot create executables …Run Code Online (Sandbox Code Playgroud) 根据facebook,截至2014年4月30日,该create_event方法已不再可用,我认为这意味着无法发布事件?
https://developers.facebook.com/docs/apps/changelog
create_event不再可用.
是否仍然可以使用v1.0?(将于2015年4月30日逐步淘汰).我找不到任何示例,我想代表facebook页面发布活动.这还有可能吗?
https://developers.facebook.com/docs/graph-api/reference/v1.0/page/events
当我尝试它时,我得到折旧警告和冒充使用令牌的页面,但是当我使用我的个人令牌时它也失败了.可能是因为我没有create_event权限(尽管请求它,它不会显示在facebook令牌调试器中)
Deprecation warning: The REST API is now deprecated; please use the equivalent Graph API methods instead. See http://developers.facebook.com/blog/post/616/.
=> {"error_code"=>190,
"error_msg"=>"Impersonated access tokens can only be used with the Graph API",
Run Code Online (Sandbox Code Playgroud)
权限:
[{"permission"=>"installed", "status"=>"granted"},
{"permission"=>"public_profile", "status"=>"granted"},
{"permission"=>"manage_pages", "status"=>"granted"},
{"permission"=>"publish_actions", "status"=>"granted"}]
Run Code Online (Sandbox Code Playgroud) 我试着提前一点思考,如果可能的话,避免自己一些额外的痛苦.
我在过去的应用程序中遇到过这个问题,并且通常选择了最冗长的方法,但是希望得到其他几个方面的意见.
如果你有一个如下所示的基本表,那么包括一个字段是明智的和/或更有效的,该字段包括可以从另外两列中找到的信息的计算.IE:
+-----+---------+------------+-------+--------+-------+
| id | room_id | bookdate | price | people | total |
+-----+---------+------------+-------+--------+-------+
| 414 | 132 | 2010-03-01 | 14.55 | 2 | 29.10 |
| 415 | 132 | 2010-03-02 | 14.55 | 2 | 29.10 |
| 416 | 132 | 2010-03-03 | 14.55 | 2 | 29.10 |
+-----+---------+------------+-------+--------+-------+
Run Code Online (Sandbox Code Playgroud)
最后一个字段中的信息可以从前两个字段的产品中提取出来,因此它是多余的,不必要的.有没有可能仍然值得拥有它的情况?
我在Notifier模型中使用了一个布局用于我的所有电子邮件(20多封电子邮件)...但有时我只想发送一个没有布局或html的纯文本电子邮件.我似乎无法弄清楚如何?如果我尝试发送纯文本电子邮件,我仍然可以获得布局,以及电子邮件中的所有HTML.
我正在使用Rails 2.3.8.
我在这里读到了关于这个猴子补丁的内容......但它似乎表明有更新版本的导轨已经过来了吗?如果我可以避免,我真的不想修补猴子.
Rails - 使用邮件程序模板为多部分电子邮件设置多个布局
layout "email" # use email.text.(html|plain).erb as the layout
def welcome_email(property)
subject 'New Signup'
recipients property.email
from 'welcome@test.com'
body :property => property
content_type "text/html"
end
def send_inquiry(inquire)
subject "#{inquire.the_subject}"
recipients inquire.ob.email
from "Test on behalf of #{inquire.name} <#{inquire.email}>"
body :inquire => inquire
content_type "text/plain"
end
Run Code Online (Sandbox Code Playgroud)
我也有2个文件.
email.text.html.erb
email.text.plain.erb
Run Code Online (Sandbox Code Playgroud)
它总是使用text.html.erb ...即使content_type是"text/plain"
我在编码字符串时遇到问题,因此我可以将变量放入链接中.我确信这很简单,但是我无法改变任何事情.
$("a.inquiry").attr("href", "/inquiry/6933/text=" + encodeURI("text o"));
Run Code Online (Sandbox Code Playgroud)
这不起作用.
encodeURI("text o")
Run Code Online (Sandbox Code Playgroud)
仍然回归:
link/text o
Run Code Online (Sandbox Code Playgroud)
代替:
link/text%20
Run Code Online (Sandbox Code Playgroud)
还尝试过:
$("a.inquiry").attr("href", encodeURIComponent("/inquiry/6933/text=" + "text o"));
Run Code Online (Sandbox Code Playgroud) 我一直在使用geokit和geokit-rails gem用于rails一段时间,但我没有找到的一个问题是如何找到计算的聚合中心的一组点.我知道如何计算两点之间的距离,但不超过2点.
我的理由是,我在同一个城市都有一系列要点...所有事情都很完美,这个城市会有一个我可以使用的中心,但是有些城市,比如说柏林没有一个完美的中心.他们有多个中心,我只想使用我在数据库中的所有地点列表来计算特定分布的中心.有没有其他人有这个问题?
有小费吗?谢谢
我想,如果用户登录后,它会自动重定向到以前的位置,但这似乎永远不会发生,它总是重定向回根位置.从阅读有关设计的文档看来,这个功能似乎只是起作用.我是以某种方式错误地使用它和/或我如何强制它存储位置和重定向无论如何?
authentication = UserToken.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => omniauth['provider']
sign_in_and_redirect(:user, authentication.user)
else
Run Code Online (Sandbox Code Playgroud) 我最近使用omniauth尝试从Google的登录信息填充某些字段时出错
Encoding :: CompatibilityError:不兼容的字符编码:ASCII-8BIT和UTF-8
"omniauth"=>
{"user_info"=>
{"name"=>"Joe McÙisnean",
"last_name"=>"McÙisnean",
"first_name"=>"Joe",
"email"=>"someemail@gmail.com"},
"uid"=>
"https://www.google.com/accounts/o8/id?id=AItOawnQmfdfsdfsdfdsfsdhGWmuLTiX2Id40k",
"provider"=>"google_apps"}
Run Code Online (Sandbox Code Playgroud)
在我的用户模型中
def apply_omniauth(omniauth)
#add some info about the user
self.email = omniauth['user_info']['email'] if email.blank?
self.name = omniauth['user_info']['name'] if name.blank?
self.name = omniauth['user_info'][:name] if name.blank?
self.nickname = omniauth['user_info']['nickname'] if nickname.blank?
self.nickname = name.gsub(' ','').downcase if nickname.blank?
unless omniauth['credentials'].blank?
user_tokens.build(:provider => omniauth['provider'],
:uid => omniauth['uid'],
:token => omniauth['credentials']['token'],
:secret => omniauth['credentials']['secret'])
else
user_tokens.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
end
end
Run Code Online (Sandbox Code Playgroud)
我对UTF编码知之甚少,所以我不确定在哪里指定编码?但是我猜它是在它被放入用户模型并创建之前,我不确定该怎么办呢?
更新:
Rails 3.0.10 Omniauth 0.2.6 Ruby 1.9.2 …