为什么gems安装在一个目录中,其Ruby版本与我正在运行的版本不同?

当我安装gem时,它被安装在一个名为1.9.1的目录中,尽管它不是我安装的Ruby版本: $ ruby -v ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0] $ gem which rails …/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails.rb 为什么会这样? 我没有安装其他Ruby版本(当然不是v1.9.1)。

为什么Ruby中的符号不​​被认为是一种变量?

编程和Ruby的新手,我希望这个关于符号的问题符合要求。 我理解Ruby中的符号(例如:book , :price )特别适合作为散列键,并且可以全面地完成字符串可以执行的轻量级特定子集。 但是,我在某方面对符号感到困惑。 具体来说,当它们在attr_accessor类型的方法中使用时,它们看起来更像是一个变量。 例如, attr_reader :book, :price 。 如果它们是该用法中的变量,那么这有点令人费解,因为它们通常不在变量类型中列出(如$ global,@ instance,local,@@ class,有时候,CONSTANT,变量类型)被描述。 如果符号是以这种方式使用的变量,那么应该对它们有什么范围? 或者它们在这种情况下仍然是某种轻量级的字符串? (或者也许以更广泛的方式,符号,字符串和变量都具有基本的鸭子性质?)提前感谢您的见解和建议。

如何要求在rails之外工作的活动记录

我需要活动记录,但我在rails之外工作(这就是为什么: 简单的Ruby输入validation库 )。 我需要整个rails gem,还是我可以DRYer?

带有has_many的counter_cache:通过

我刚刚创建了一个counter_cache字段,控制器看起来像这样。 @users = User.where(:sex => 2).order(‘received_likes_count’) User.rb中的关联是 has_many :received_likes, :through => :attachments, :source => :likes, :dependent => :destroy 问题是counter_cache是​​在Like.rb的belongs_to中声明的,我不知道如何告诉它是为了has_many:通过关联。 belongs_to :user, :counter_cache => :received_likes

如何在Sass中使用Ruby / Rails变量?

有没有办法在Sass文件中使用我的Ruby应用程序中的变量?

如何使Ruby AES-256-CBC和PHP MCRYPT_RIJNDAEL_128一起发挥得很好

我正在生成要从Ruby堆栈发送到PHP堆栈的数据。 我在Ruby端使用OpenSSL :: Cipher库,在PHP使用’mcrypt’库。 当我在Ruby中使用’aes-256-cbc’(256位块大小)进行加密时,我需要在PHP中使用MCRYPT_RIJNDAEL_128(128位块大小)来解密它。 我怀疑Ruby代码被破坏了,因为cipher.iv_len是16; 我相信它应该是32: >> cipher = OpenSSL::Cipher::Cipher.new(‘aes-128-cbc’) => # >> cipher.key_len => 16 >> cipher.iv_len => 16 >> cipher = OpenSSL::Cipher::Cipher.new(‘aes-256-cbc’) => # >> cipher.key_len => 32 >> cipher.iv_len => 16 所以这是我的考试。 在Ruby方面,首先我生成密钥和iv: >> cipher = OpenSSL::Cipher::Cipher.new(‘aes-256-cbc’) >> cipher.encrypt >> iv = cipher.random_iv >> iv64 = [iv].pack(“m”).strip => “vCkaypm5tPmtP3TF7aWrug==” >> key […]

自动加载常量用户时检测到循环依赖性

我已经按照本教程( http://railscasts.com/episodes/236-omniauth-part-2 )使用OmniAuth和Devise创建facebook登录,我收到此错误:在我的路由中自动加载常量用户时检测到循环依赖性。 RB devise_for :users , :controllers => {:registrations => ‘registrations’} registrations_controller.rb Class RegistrationsController < Devise::RegistrationsController def create super session[:omniauth] = nil unless @user.new_record? end private def build_resource(*args) super if session["devise.omniauth"] @user.apply_omniauth(session["devise.omniauth"]) session["devise.omniauth"] = nil end end end 这是来自AuthenticationsController的我的创建方法 def create omniauth = request.env[“omniauth.auth”] authentication = Authentication.find_by_provider_and_uid(omniauth[‘provider’], omniauth[‘uid’]) if authentication flash[:notice] = “Signed in […]

“gem install rails”因DNS错误而失败

$ rvm use Using /home/owner/.rvm/gems/ruby-2.1.2 $ gem install rails ERROR: While executing gem … (Gem::RemoteFetcher::FetchError) Errno::ECONNREFUSED: Connection refused – connect(2) for “your-dns-needs-immediate-attention.network” port 80 (http://your-dns-needs-immediate-attention.network/quick/Marshal.4.8/thread_safe-0.3.4.gemspec.rz) $ gem update –system … $ gem -v 2.4.1 $ gem install rails ERROR: While executing gem … (Gem::RemoteFetcher::FetchError) Errno::ECONNREFUSED: Connection refused – connect(2) for “your-dns-needs-immediate-attention.network” port 80 (http://your-dns-needs-immediate-attention.network/quick/Marshal.4.8/rails-4.1.5.gemspec.rz) 我试过了: […]

如何使用open-uri发出POST请求?

是否可以使用open-uri从Ruby发出POST请求?

你可以在Ruby中调用者的上下文中评估代码吗?

基本上我想知道以下是否可以在Ruby中完成。 例如: def bar(symbol) # magic code goes here, it outputs “a = 100” end def foo a = 100 bar(:a) end