我有以下代码:
http = Net::HTTP.new("www.something.com", 80)
http.set_debug_output($stdout)
http.post("/blah", "something", {'random-parameter' => 'value1="something",value2="somethingelse"'})
Run Code Online (Sandbox Code Playgroud)
然后,当我从stdout读取输出时,它看起来像这样:
<- "POST /blah HTTP/1.1\r\nAccept: */*\r\nContent-Type: application/x-www-form-urlencoded\r\nConnection: close\r\nrandom-parameter: value1=\"something\",value2=\"somethingelse\"\r\nContent-Length: 9\r\nHost: www.something.com\r\n\r\n"
<- "something"
Run Code Online (Sandbox Code Playgroud)
引号被转义.问题是斜线似乎被发送到服务器,这不喜欢.我收到的错误是
Unknown value for random-parameter in header: {value1=\\\"something\\\"value2=\\\"somethingelse\\\"}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,有没有办法让Net :: HTTP不插入这些斜杠,或者在发送标题之前将其删除?
澄清:
我正在使用Ruby 1.8.7和Rails 2.0.2.
我认为可能是Rails正在逃避角色,但我不知道如何让它停止.
我已经创建了一个名为gemset rails2ruby192,我.rvmrc在根文件目录中添加了以下代码,但它没有加载gemset.
ruby-1.9.2-p180@rails2ruby192
Run Code Online (Sandbox Code Playgroud) 哪个版本的rspec-railsgem仍与Rails 2.3分支兼容(特别是2.3.14)?我试过了2.1.0,但那个也是Rails> = 3.0.我应该注意的任何其他依赖项或版本限制?
谢谢.
我尝试运行2.x应用程序.我使用rvm并为此应用程序设置其他版本的ruby:
$ rvm use ree-1.8.7-head
Run Code Online (Sandbox Code Playgroud)
我尝试运行服务器,然后我收到很多错误:
$ script/server
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#refresh! is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /Users/serg/.rvm/rubies/ree-1.8.7-head/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:127.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /Users/serg/.rvm/rubies/ree-1.8.7-head/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:127.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from …Run Code Online (Sandbox Code Playgroud) 我对使用问号之间的差异感到困惑,例如
Foo.find(:all, :conditions => ['bar IN (?)', @dangerous])
Run Code Online (Sandbox Code Playgroud)
并使用sprintf样式字段类型,例如
Bar.find(:all, :conditions => ['qux IN (%s)', @dangerous])
Run Code Online (Sandbox Code Playgroud)
消毒投入.是否有任何安全优势,如果你知道你正在寻找一个数字 - 比如一个ID - 而不是一个字符串,在使用%d over?,或者你只是在字符串出现时要求一个大的讨厌错误?
Rails 3和4中的更新.where语法是否会发生这种变化?
ruby ruby-on-rails sanitize ruby-on-rails-2 rails-activerecord
我有一个遗留的Rails应用程序,我想升级到最近的Rails和Ruby版本.首先,我试图用Ruby 2.1.2设置应用程序
$ rails -v
Rails 2.3.18
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [i686-linux]
Run Code Online (Sandbox Code Playgroud)
当我尝试运行rake任务时rake db:schema:load RAILS_ENV=test遇到错误
can not load translations from /activesupport-2.3.18/lib/active_support/locale/en.yml, the file type yml is not known
Run Code Online (Sandbox Code Playgroud)
通过Google搜索我发现以下参考https://github.com/rails/rails/issues/10514,其中提到Rails 2.3和Ruby 2+版本之间存在不兼容性.
任何人都可以帮我申请参考链接中提到的猴子补丁吗?
谢谢,Jignesh
我有一个名为“Pages”的控制器,其中包含大约 5 个页面(视图),我为其呈现了一个名为“page.html.erb”的布局。所以我的“页面”控制器有:
class PagesController < ApplicationController
layout 'page'
Run Code Online (Sandbox Code Playgroud)
我希望我的“page.html.erb”布局默认使用“application.html.erb”。如何让我的自定义布局“page.html.erb”自动继承/呈现“application.html.erb”?
如果我使用2.5.1带有rails版本的ruby版本会发生什么2.3.18?
我在rails 2.3.18和ruby 上构建了rails应用程序1.9.2p320,我想升级ruby版本而不是rails它是否可能?
我必须面对的挑战是什么?
我有一个有很多孩子的简单父对象.我正在试图弄清楚如何使用命名范围来带回具有特定数量的孩子的父母.
这可能吗?
class Foo < ActiveRecord::Base
has_many :bars
named_scope :with_no_bars, ... # count of bars == 0
named_scope :with_one_bar, ... # count of bars == 1
named_scope :with_more_than_one_bar, ... # count of bars > 1
end
class Bar < ActiveRecord::Base
belongs_to :foo
end
Run Code Online (Sandbox Code Playgroud)
我希望能做类似的事情 Foo.with_one_bar
我可以在父类上编写类似这样的方法,但我宁愿拥有命名范围的强大功能
我用Rails 2工作,我有三个表:users,lms_users和group_details.
在lms_usersid users和group_details来自外键.lms_users也有自己的属性.我无法在各自的模型中定义关联.我试过这个:
在LmsUser模型中
belongs_to :users
belongs_to :group_details
Run Code Online (Sandbox Code Playgroud)
在User模型中
has_many :group_details , :through => :lms_users
Run Code Online (Sandbox Code Playgroud)
在GroupDetail模型中
has_many :users , :through => :lms_users
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误
ActiveRecord::ConfigurationError in Lms usersController#index
Association named 'lms_user' was not found; perhaps you misspelled it?
Run Code Online (Sandbox Code Playgroud) ruby-on-rails-2 ×10
ruby ×5
activerecord ×1
named-scope ×1
rspec-rails ×1
ruby-1.8 ×1
ruby-1.9.3 ×1
ruby-2.1 ×1
ruby-2.5 ×1
rvm ×1
rvmrc ×1
sanitize ×1
webrick ×1