Tag: ruby

如何在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

*(星级)在Ruby中意味着什么?

可能重复: 什么是*运算符在Ruby中对此字符串执行的操作 可能在其他地方有答案,但我只是不知道如何找到它… 如果我是对的, *表示在函数定义中使用的多个参数: def hero(name, *super_powers) 但是*在代码中做了什么: Hash[*[[:first_name, ‘Shane’], [:last_name, ‘Harvie’]].flatten] # => {:first_name=>”Shane”, :last_name=>”Harvie”}

POST json到rails服务器

def create req = ActiveSupport::JSON.decode(request.body) if user = User.authenticate(req[“email”], req[“password”]) session[:user_id] = user.id render :json => “{\”r\”: \”t\”}” + req else render :json => “{\”r\”: \”f\”}” end end ‘create’方法在控制器中并映射到“/ login”,我正在设置正确的内容类型并从我的curl客户端接受标头。 我一直收到422 http状态响应。 有什么建议?

使用Selenium模仿将文件拖到上传元素上

我有一个网页,当你点击一个按钮时打开一个div。 此div允许您将文件从桌面拖到其区域; 然后该文件上传到服务器。 我正在使用Selenium的Ruby实现。 通过在Firefox中使用JavaScript调试器,我可以看到一个名为“drop”的事件正被传递给某些JavaScript代码“handleFileDrop(event)”。 我认为如果我要创建一个模拟事件并以某种方式触发它我可以触发此代码。 如果发现一篇有趣的文章似乎指向了一个很有希望的方向,但我仍然没有把它全部搞清楚。 我可以使用Selenium的get_eval方法将JavaScript传递给页面。 使用this.browserbot调用方法让我获得了我需要的元素。 所以: 如何构建需要成为模拟放置事件一部分的文件对象? 如何触发掉落事件,使其被拾取,好像我在div中删除了一个文件?

ROR +无法安装tiny_tds

在这里,我试图从MS-SQL Server 2008获取数据到Ubuntu 10上的我的Rails应用程序。但是我无法安装tiny_tds 。 我按照github给出的步骤进行操作。 但没有回应。 请指导我正确设置。 使用gem命令:: gem install tiny_tds 这个命令也是:: gem install tiny_tds –with-freetds-include=/usr/local/include/freetds –with-freetds-lib=/usr/local/lib 错误: Installing tiny_tds (0.4.5) with native extensions /home/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions’: ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError) /home/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb looking for library directory /home/.rvm/gems/ruby-1.9.2-p180@rails3/lib … no looking for library directory /home/.rvm/gems/ruby-1.9.2-p180@rails3/lib/freetds … no […]