我有一个ID为"link"的链接,我使用下面的javascript在modalbox中打开该链接:
#In my template I have:
<a href="some/path" id="link">link</a>
#Then in my application.js file I have:
document.observe('dom:loaded', function() {
$('link').observe('click', function(event) {
event.stop();
Modalbox.show(this.href,{title: 'some title', width: 500});
});
})
Run Code Online (Sandbox Code Playgroud)
因为id必须是唯一的,所以这个javascript只适用于每页一个元素,所以我用它来观察我的登录链接,它对我很有帮助.到现在.
我想使用相同的JavaScript来观察具有类名而不是id的多个链接,如下所示:
<a href="link/to/some/stuff" class="link">link 1</a>
<a href="link/to/some/other/stuff" class="link">link 2</a>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我无法在模态框中打开任何链接.如果我将类更改为每个链接的id,那么我可以获取列表中的第一个链接以在模态框中打开.
我尝试使用'$$'符号在我的javascript中构建一个链接数组(如下所示),但如果我这样做,那么没有一个链接正确打开
#document.observe method removed for display purposes
$$('link').observe('click', function(event) {
event.stop();
Modalbox.show(this.href,{title: 'some title', width: 500} );
});
Run Code Online (Sandbox Code Playgroud)
我的javascript技能显然很糟糕.
有谁知道如何解决这个问题?
我的规范中有以下内容:
before do
@item = Item.new( title: "Lorem ipsum",
image: File.new(Rails.root.join('app', 'assets', 'images', 'rails.png')))
end
Run Code Online (Sandbox Code Playgroud)
相关规范需要大约 30 秒才能运行,但当我image: File.new()从哈希中删除时,我的测试运行时间不到 1 秒!
因此,File.new()向我的规格添加负载也是如此,如果可能的话,我想将其存根,但是当我尝试这样做时:
image: File.stub(Rails.root.join('app', 'assets', 'images', 'rails.png')))
Run Code Online (Sandbox Code Playgroud)
我在测试输出中看到以下错误:
Failure/Error: image: File.stub(Rails.root.join('app', 'assets', 'images', 'rails.png'))) }
NoMethodError:
undefined method `to_sym' for #<Pathname:0xae767d8>
Run Code Online (Sandbox Code Playgroud)
如果有任何建议,我将不胜感激。FWIW,图像上传是由回形针处理的。
我正在尝试使用 Rails 将带连字符的单词的两个部分都大写:
"hello-world".capitalize
# => Hello-world
"hello-world".titleize
# => Hello World
Run Code Online (Sandbox Code Playgroud)
有没有一种快速的方法来做到这一点?如果没有,那么我将编写一个自定义解决方案,我可以解决这个问题,但我希望有一些非常快速和肮脏的方法可以为我做到这一点
我正在关注railstutorial.org教程我收到以下错误
1) User pages signup with valid information should create a user
Failure/Error: fill_in "password" , with: "foobar"
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'password' found
# (eval):2:in `fill_in'
# ./spec/requests/user_pages_spec.rb:32:in `block (4 levels) in <top (required)>'
2) Authentication signin with invalid information
Failure/Error: before { click_button "Sign in" }
Capybara::ElementNotFound:
no button with value or id or text 'Sign in' found
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:14:in `block (4 …Run Code Online (Sandbox Code Playgroud) 我有一个密码重置邮件程序,我希望能够在我的测试中执行以下操作:
assert_match edit_password_reset_path(user.password_reset_token), mail.body.encoded
# undefined method `edit_password_reset_path' for #<UserMailerTest:0xb6c2ea0>
Run Code Online (Sandbox Code Playgroud)
但是由于URL帮助器,它会爆炸,所以我必须这样做才能让我的测试运行:
assert_match "\/password_resets\/#{user.password_reset_token}\/edit", mail.body.encoded
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,但不要看,或感觉,这么好.
似乎ActionMailer :: TestCase不知道路径,因为以下失败:
assert_match "#{edit_password_reset_path(user.password_reset_token)}", mail.body.encoded
# undefined method `edit_password_reset_path' for #<UserMailerTest:0xb6c2ec8>
Run Code Online (Sandbox Code Playgroud)
你如何访问edit_password_reset_path(user.password_reset_token)测试单元中的URL助手?
我从RSpec切换到哪里这从来都不是问题,助手刚刚工作,我会这样做:
it "sends the user a password reset url" do
mail.body.encoded.should match(edit_password_reset_url(user.password_reset_token))
end
Run Code Online (Sandbox Code Playgroud) 我想从下面的代码中替换所有4个数字300的实例(我的网站用户将在创建新博客文章时粘贴它),使用470.
<div>
<object width="300" height="300">
<embed src="link-removed" width="300" height="300"></embed>
</object>
<p>
<a href="another-link">link</a>
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
要粘贴的代码的宽度和高度可能不总是300乘300.
所以我想我可能需要一个正则表达式,它包含字符串"width ="和"height ="之后的任何数值,同时记住要考虑数字周围的引号.任何人都可以告诉我,这是最好的方式,如果是这样,最好的正则表达式是什么?
如果它很重要,被粘贴的代码将作为"文本"存储在数据库中而不是字符串中,因为它非常冗长(我已从您在此处粘贴的内容中删除了几百个字符)...
我有一个烦人的IE6布局错误
此屏幕截图显示了问题:

问题:文本输入即<input type='text' />大小错误.
文本输入有点不稳定.它们应该是248px宽(像textarea)并且与它们的标签处于相同的水平面上.所有其他浏览器似乎遵守以下代码,但我们的朋友IE6没有
.simple_form input[type='text'],.simple_form input[type='email'],.simple_form textarea
{
width:240px;
border:1px solid #ccc;
padding:3px
}
Run Code Online (Sandbox Code Playgroud)
我不知道我在这里做错了什么,这让我疯了.有问题的页面在这里.IE6中的输入明显宽于248px.input[type='text']在CSS中使用IE6 时是否有问题?
可以发布更多代码
我这样切换到root用户:
$ sudo su -
Run Code Online (Sandbox Code Playgroud)
然后我尝试运行类似的东西 birdc
[root@localhost ~]# birdc
Unable to connect to server control socket (/usr/local/var/run/bird.ctl):
No such file or directory
Run Code Online (Sandbox Code Playgroud)
我发现我仍然需要sudo运行如上所示的命令:
[root@localhost ~]# sudo birdc
BIRD 1.4.2 ready.
bird>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?这与我安装BIRD的方式有关吗?