一直在使用Ruby on Rails并决定查看实际来源.抓住GitHub的回购并开始环顾四周.遇到一些代码,我不知道它做了什么或它引用了什么.
我在actionmailer/test/abstract_unit.rb中看到了这段代码
root = File.expand_path('../../..', __FILE__)
begin
require "#{root}/vendor/gems/environment"
rescue LoadError
$:.unshift("#{root}/activesupport/lib")
$:.unshift("#{root}/actionpack/lib")
end
lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
require 'rubygems'
require 'test/unit'
require 'action_mailer'
require 'action_mailer/test_case'
Run Code Online (Sandbox Code Playgroud)
有人能告诉我$ :(又名"bling")引用了什么?
我试图在我的OSX Mountain Lion上安装cocoapods(http://cocoapods.org/).
moshe-mbp:~ moshem$ gem install cocoapods
ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server key exchange B: bad ecpoint (https://rubygems.org/latest_specs.4.8.gz)
Run Code Online (Sandbox Code Playgroud)
我先试过
rvm reinstall all --force
Run Code Online (Sandbox Code Playgroud)
然后我试了
brew upgrade openssl
==> Upgrading openssl
==> Downloading http://openssl.org/source/openssl-1.0.1e.tar.gz
Already downloaded: /Library/Caches/Homebrew/openssl-1.0.1e.tar.gz
==> perl ./Configure --prefix=/usr/local/Cellar/openssl/1.0.1e --openssldir=/usr/local/etc/openssl zlib-dynamic shared d
==> make
==> make test
==> make install MANDIR=/usr/local/Cellar/openssl/1.0.1e/share/man MANSUFFIX=ssl
==> Caveats …Run Code Online (Sandbox Code Playgroud) 我有一个jQuery脚本,它向表单添加一个新字段,该字段包含一个数组的动态信息.问题是我无法弄清楚如何添加一个array.each来填充javascript中select字段的选项而不会破坏HAML缩进并导致错误.
这是我最好的尝试,不起作用:
%script(type="text/javascript")
$('#mylink').click(function() {
$('#mylink').after('<select>
- myarray.each do |options|
<option value="#{options.id}">#{options.name}</option>
</select>);
)};
Run Code Online (Sandbox Code Playgroud)
还尝试使用:javascript过滤器,没有运气.
我在我的一个程序上运行了ruby-profiler.我想弄清楚每个字段的含义.我猜测一切都是CPU时间(而不是挂钟时间),这太棒了.我想了解"---"代表什么.那里有某种堆栈信息.调用a/b是什么意思?
Thread ID: 81980260
Total Time: 0.28
%total %self total self wait child calls Name
--------------------------------------------------------------------------------
0.28 0.00 0.00 0.28 5/6 FrameParser#receive_data
100.00% 0.00% 0.28 0.00 0.00 0.28 6 FrameParser#read_frames
0.28 0.00 0.00 0.28 4/4 ChatServerClient#receive_frame
0.00 0.00 0.00 0.00 5/47 Fixnum#+
0.00 0.00 0.00 0.00 1/2 DebugServer#receive_frame
0.00 0.00 0.00 0.00 10/29 String#[]
0.00 0.00 0.00 0.00 10/21 <Class::Range>#allocate
0.00 0.00 0.00 0.00 10/71 String#index
--------------------------------------------------------------------------------
100.00% 0.00% 0.28 0.00 0.00 0.28 5 FrameParser#receive_data
0.28 0.00 0.00 0.28 5/6 …Run Code Online (Sandbox Code Playgroud) 当我运行Ruby命令时,gem -v我收到此错误:
/Users/kristoffer/.rvm/rubies/ruby-1.9.2-p180/bin/gem:4:警告:不安全的世界可写dir /用户/ kristoffer在PATH中,模式040777
1.6.2
首先,我不明白这意味着什么./ Users/kristoffer不在我的路径中echo $PATH.结果echo $PATH是:
/Users/kristoffer/.rvm/gems/ruby-1.9.2-p180/bin:/Users/kristoffer/.rvm/gems/ruby-1.9.2-p180@global/bin:/Users/kristoffer/.rvm/红宝石/红宝石1.9.2-P180 /斌:/Users/kristoffer/.rvm/bin:在/ usr/bin中:/ bin中:/ usr/sbin目录:/ sbin目录:在/ usr/local/bin目录:在/ usr/X11 /箱子
如您所见,PATH非常干净.只是默认路径+ RVM添加的内容.
我已经看到其他类似的帖子,其中解决问题的推荐方法是运行 chmod go-w path/to/folder
但是,我很确定让我的Home文件夹不可写是一个坏主意,对吧?我已使用"磁盘工具"修复了权限,但未发现我的主文件夹上的权限有任何问题.
知道问题是什么以及我如何解决它?
我正在使用JPEGCAM来允许用户使用他们的网络摄像头拍摄个人资料照片.这会上传一个临时文件,如下所示:
def ajax_photo_upload
File.open(upload_path, 'w:ASCII-8BIT') do |f|
f.write request.raw_post
end
# @user.photo = File.open(upload_path)
@user.assign_attributes(
:photo => File.open(upload_path),
:orig_filename => "#{current_user.full_name}.jpg"
)
if @user.save
respond_to do |format|
.....
private
def upload_path # is used in upload and create
file_name = session[:session_id].to_s + '.jpg'
File.join(::Rails.root.to_s, 'public', 'temp', file_name)
end
Run Code Online (Sandbox Code Playgroud)
安全删除此临时文件的最佳方法是什么?谢谢
在Ruby 2.0.0-p0中,__dir__引入了变量以便于访问当前正在执行的文件的目录.
为什么__dir__大写时__FILE__是小写的?
每当我做bundle install所有的宝石安装在
app_dir/vendor/bundle
Run Code Online (Sandbox Code Playgroud)
路径并消耗大量磁盘空间.我也尝试安装宝石,它应该安装,即宝石集,而开发由此:
bundle install --no-deployement
Run Code Online (Sandbox Code Playgroud)
但这对我来说并不适合安装宝石vendor/bundle.如何让它全局安装在所有应用程序或ruby gemsets位置?我也试过删除.bundle/config但没有改变.
我在用:
rvm version: 1.23.14
ruby version: 2.0.0-p247
rails 3.2.13
Run Code Online (Sandbox Code Playgroud)
这是我的~/.bash_profile:
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
eval "$(rbenv init -)"
alias pg='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log'
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
Run Code Online (Sandbox Code Playgroud)
我的~/.bashrc:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Run Code Online (Sandbox Code Playgroud)
您可能需要的其他一些信息:
aman@Amandeeps-MacBook-Pro …Run Code Online (Sandbox Code Playgroud) 我发现我的Rails代码中存在内存泄漏 - 也就是说,我发现了代码泄漏但不泄漏的原因.我把它减少到不需要Rails的测试用例:
require 'csspool'
require 'ruby-mass'
def report
puts 'Memory ' + `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)[1].to_s + 'KB'
Mass.print
end
report
# note I do not store the return value here
CSSPool::CSS::Document.parse(File.new('/home/jason/big.css'))
ObjectSpace.garbage_collect
sleep 1
report
Run Code Online (Sandbox Code Playgroud)
据说红宝石质量可以让我看到记忆中的所有物体.CSSPool是一个基于racc的CSS解析器./home/jason/big.css是一个1.5MB的CSS文件.
这输出:
Memory 9264KB
==================================================
Objects within [] namespace
==================================================
String: 7261
RubyVM::InstructionSequence: 1151
Array: 562
Class: 313
Regexp: 181
Proc: 111
Encoding: 99
Gem::StubSpecification: 66
Gem::StubSpecification::StubLine: …Run Code Online (Sandbox Code Playgroud) 我在OS X 10.9.3 MacBook Pro上通过Homebrew安装了rbenv.
我做了:
brew update
brew upgrade rbenv ruby-build
Run Code Online (Sandbox Code Playgroud)
根据rbenv install --list我的笔记本电脑Ruby 2.1.0-dev是最新的.
有谁知道这是关于什么的?我猜这是一个10.9.3的问题.