基本上,比这更好的东西:
<input type="file" name="myfile" size="50">
Run Code Online (Sandbox Code Playgroud)
首先,browse每个浏览器上的按钮看起来都不同.与submit表单上的按钮不同,您必须采用一些hack-y方式来设置它.
其次,没有进度指示器显示文件已上传了多少.您通常必须实现某种客户端方式来禁用多个提交(例如,将提交按钮更改为显示"表单提交...请等待."的禁用按钮)或闪烁一个巨大的警告.
有没有好的解决方案,不使用Flash或Java?
Yaakov:该产品看起来正是我正在寻找的,但成本是1000美元,它专门用于ASP.NET. 是否有任何开源项目涵盖相同或类似的功能?
关于RJS最方便的一点是它能够渲染部分内容,因此您可以在一个地方拥有所有视图代码:
# task/index.html.erb
<ul id="task_list">
<%= render :partial => 'task', :collection => @tasks %>
</ul>
# task/_task.html.erb
<li>
<% if task.is_completed %>
<%= task.name %> - <%= task.completed_date %>
<% else %>
<%= task.name %> - UNCOMPLETED
<% end %>
...
</li>
Run Code Online (Sandbox Code Playgroud)
现在我正试图摆脱RJS并让服务器以一个小的,格式良好的JSON而不是大量的JS + HTML进行响应.
有没有办法保持我的部分文件和代码没有重复,并能够通过JS添加新项目而不使用RJS?我已经研究了一些javascript模板引擎,但它们都需要我维护一个单独的ruby部分和一个javacript模板.
我有一堆图像需要每2秒一次旋转进出一个花哨的JQuery fadeIn和fadeOut.我有HTML中的所有图像来预加载它们和一个setInterval计时器,它会淡化当前图像,然后淡化下一个图像.问题是有时当你在淡入/淡出过程中点击或滚动时, JS被打断了,当前的图像永远不会消失,下一个图像会给你两张图片.
我觉得它与setInterval每2秒运行不正常有关,但有没有更好的方法来完成我需要的东西?
这是一段代码:
HTML
<a href="javascript:;">
<img id="img1" src="image1.gif" />
<img id="img2" src="image2.gif" style="display:none;" />
<img id="img3" src="image3.gif" style="display:none;" />
</a>
Run Code Online (Sandbox Code Playgroud)
JS
var numImages = 3;
var currentImage = 1;
imageInterval = window.setInterval("changeImage();", 2000);
function changeImage()
{
$("#img" + currentImage).fadeOut("slow", function() {
if (currentImage >= numImages)
{
currentImage = 0;
}
$("#img" + (currentImage + 1) ).fadeIn("slow", function() {
currentImage++;
});
});
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用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) 在允许用户编辑员工信息之前,我需要确保用户具有正确的权限.具体而言,用户必须是管理员,并且用户必须与员工属于同一公司.做这样的事情最好的方法是什么?
def EmployeesController < ApplicationController
before_filter :requires_admin_from_company(cid)
# Only allow access to this if user.admin is true and user.company_id is equal to employee.company_id
def update
# Somehow pass @employee.company_id into admin
@employee = Employee.find(params[:id])
@employee.update_attributes(params[:employee])
end
def requires_admin_from_company(cid)
if !@current_user.admin? || @current_user.company_id != cid
redirect_to login_url
end
end
end
Run Code Online (Sandbox Code Playgroud) 邮局实际上在地址中公布了常用的街道后缀列表:
http://www.usps.com/ncsc/lookups/abbr_suffix.txt
我想取这个列表并制作一个带字符串的ruby函数,取最后一个字("183 main strt".split [''] .last)并且它是否匹配任何常用的街道后缀("strt") ),将其替换为官方邮政服务标准后缀("st").
有没有比大规模str.sub.sub.sub.sub.sub.sub更好的方法来解决这个问题?