我正在构建某种代理.
当我在机架应用程序中调用某个URL时,我会将该请求转发给其他URL.
我转发的请求是带有文件和一些参数的POST.
我想添加更多参数.
但文件可能很大.所以我发送它Net::HTTP#body_stream代替Net::HTTP#body.
我得到了我的请求作为Rack::Request对象,我用它创建我的Net :: HTTP对象.
req = Net::HTTP::Post.new(request.path_info)
req.body_stream = request.body
req.content_type = request.content_type
req.content_length = request.content_length
http = Net::HTTP.new(@host, @port)
res = http.request(req)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了几种方法来添加代理的参数.但似乎Net :: HTTP中的任何内容都不允许向body_stream请求添加参数,只允许向body_stream请求添加参数.
是否有更简单的方法来代理这样的机架请求?或者将我的参数添加到我的请求的干净方法?
<% semantic_form_for(@product, :html => {:multipart => true}) do |f| %>
<% f.inputs do %>
<%= f.input :name %>
<%= f.input :price %>
<%= f.input :pno %>
<%= f.input :description %>
<%= f.input :shop_category %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
产品属于Shop_category,Shop_category属于Shop.
如何更改线路:
<%= f.input :shop_category %>
Run Code Online (Sandbox Code Playgroud)
要仅显示属于具有id的商店的shop_categories,例如15,而不是在选择框中显示所有shop_categories?
我有一个嵌套属性的模型:
class Foo < ActiveRecord::Base
has_many :bar
accepts_nested_attributes_for :bar
end
Run Code Online (Sandbox Code Playgroud)
它工作正常.但是我想确保每一个Foo,我至少有两个Bar.我无法访问bar_attributes我的验证,所以我似乎无法验证它.
有没有干净的方法呢?
几个月后没有看emberjs,我现在试图回到它,我正在尝试新的路由器.我想测试我的路线.
有没有人试图用emberjs写一些路由测试?
让我们假设以下路由器非常基本:
App.Router = Ember.Router.extend({
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/',
connectOutlets: function(router, context) {
router.get('applicationController').connectOutlet({name: 'home'});
}
})
})
})
Run Code Online (Sandbox Code Playgroud)
你如何测试加载root.index路线正确加载HomeView?
我有一个rsa.PublicKey对象(从 rsa.PrivateKey 中检索)。我正在尝试将其导出为 OpenSSH 格式,以在网页中显示它。
我注意到go.crypto/ssh 库,它似乎正在这样做。
还有关于它的实现的讨论(这实际上正是我需要做的)
不幸的是,我有点卡住了,因为返回的字节数组采用未知编码,我不能将其转换为字符串来显示它。
func PublicKey(rsaKey rsa.PublicKey) string {
key, _ := ssh.NewPublicKey(&rsaKey)
marshalled := ssh.MarshalPublicKey(key)
return string(marshalled)
}
Run Code Online (Sandbox Code Playgroud)
这似乎有效,因为它ssh-rsa在字符串的开头添加了。但是,大多数字符无法识别。
这是我正在为 lambda 公钥检索的字节数组:
[0 0 0 7 115 115 104 45 114 115 97 0 0 0 3 1 0 1 0 0 0 65 0 178 153 15 73 196 125 250 140 212 0 174 106 77 27 138 59 106 19 100 43 35 …
我不是一个java开发人员.但我现在正在研究Android应用程序开发,所以我做了一些怀旧,在没有触及它三年之后再做一些java.
我期待使用"google-api-translate-java"库.
其中有一个语言类.这是一个enum,允许提供语言名称,并为谷歌翻译获得它的价值.
我可以很容易地得到所有的价值:
for (Language l : values()) {
// Here I loop on one value
}
Run Code Online (Sandbox Code Playgroud)
但我想得到的是所有键名称的列表(法语,英语,......).
是否有类似"keys()"方法的东西允许我遍历所有枚举键?
我有以下路线:
@resource 'groups', {path: 'events/:event_id/groups'}, ->
@route 'new'
Run Code Online (Sandbox Code Playgroud)
在我的新路径中,为了构建一个新的App.Group对象,我需要知道我们所处的事件.
所以我有以下路线,它对应于资源:
App.GroupsRoute = Ember.Route.extend
model: (params) ->
App.Event.find params.event_id
Run Code Online (Sandbox Code Playgroud)
和路线对应的那个:
App.GroupsNewRoute = Ember.Route.extend
model: ->
App.store.createRecord App.Group
Run Code Online (Sandbox Code Playgroud)
我需要在创建时指定组的事件.但是,在GroupsNewRoute中,我似乎无法检索事件.参数不包括在内event_id.
如何从路径中的父资源获取模型?
我已经使用了bash大约3个月了。
我正在逐步理解该语言,但我有一个问题。
bash中的真正含义$与C相同吗?
我的意思是$not $1、等等。$0只有
$。$#
我正在根据模型的数据定义ChoiceField.
field = forms.ChoiceField(choices=[[r.id, r.name] for r in Model.objects.all()])
Run Code Online (Sandbox Code Playgroud)
但是我想用空的选项前置我的选项以选择"否"对象.但我找不到一个好的方法来预先设置.
我所有的测试都像:
field = forms.ChoiceField(choices=[[0, '----------']].extend([[r.id, r.name] for r in Model.objects.all()]))
Run Code Online (Sandbox Code Playgroud)
返回"无类型对象不可迭代"错误.我到目前为止找到的唯一方法如下:
def append_empty(choices):
ret = [[0, '----------']]
for c in choices:
ret.append(c)
return ret
Run Code Online (Sandbox Code Playgroud)
当我定义我的领域时:
forms.ChoiceField(choices=append_empty([[r.id, r.name] for r in
Restaurant.objects.all()]), required=False)
Run Code Online (Sandbox Code Playgroud)
但是,我想保持我的代码干净,没有那种恐怖.你有想法吗?:p谢谢你提前.
我试图使用rails插入多个表..我有一个名为用户和服务的表.当我创建用户时,用户详细信息应该进入用户,服务名称和用户ID应该进入服务表.任何帮助都会受到极大的关注.
谢谢.
我正在尝试使用Ruby 1.9和Rails 2.3.5运行一个空白的默认性能测试,但我无法让它工作!我在这里失踪了什么?
rails testapp
cd testapp
script/generate scaffold User name:string
rake db:migrate
rake test:benchmark
Run Code Online (Sandbox Code Playgroud)
-
/usr/local/bin/ruby19 -I"lib:test" "/usr/local/lib/ruby19/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/performance/browsing_test.rb" -- --benchmark
Loaded suite /usr/local/lib/ruby19/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
/usr/local/lib/ruby19/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in `rescue in const_missing': uninitialized constant BrowsingTest::STARTED (NameError)
from /usr/local/lib/ruby19/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:94:in `const_missing'
from /usr/local/lib/ruby19/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/testing/performance.rb:38:in `run'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:415:in `block (2 levels) in run_test_suites'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:409:in `each'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:409:in `block in run_test_suites'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:408:in `each'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:408:in `run_test_suites'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:388:in `run'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:329:in `block in autorun'
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby19 -I"lib:test" "/usr/l...]
Run Code Online (Sandbox Code Playgroud) 我想转换字符串
"Full Time"
Run Code Online (Sandbox Code Playgroud)
至
"full_time"
Run Code Online (Sandbox Code Playgroud)
当我在irb中使用"Full Time".underscore时,它会提示错误
NoMethodError: undefined method `underscore' for "Full Time":String
Run Code Online (Sandbox Code Playgroud)
我该如何解决?或者还有其他方法可以让我获得上述强调结果吗?
我想从php中的列表框上传文件.
我能够通过使用<input type="file">我在http://www.tizag.com/phpT/fileupload.php上找到的内容来实现
但是,当我改变这种<input type="file">通过<select>
我正在尝试这种方式
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" />
<select name="uploadedfile" id = "fileName" size="3" style="width: 100%">
<option id = "uploadedfile" value="c:\text.txt">c:\text.txt</option>
</select>
<input type="submit" value="Upload File" />
</form>
Run Code Online (Sandbox Code Playgroud)
两种情况下PHP代码保持不变
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['value']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['value']).
" has been uploaded";
} else{
echo "There …Run Code Online (Sandbox Code Playgroud) ruby ×4
ember.js ×2
forms ×2
activerecord ×1
bash ×1
callback ×1
choicefield ×1
django ×1
dollar-sign ×1
ember-router ×1
enums ×1
formtastic ×1
go ×1
http ×1
java ×1
php ×1
proxy ×1
python ×1
rack ×1
ssh ×1
upload ×1