我遇到以下问题:
我在整个网站上都有一个登录表单(请参阅https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app):
# application.html.haml
...
= form_tag new_user_session_path do
= text_field_tag 'user[email]'
= password_field_tag 'user[password]'
%button Login
我想用黄瓜测试填写我的注册表格:
# register#new.html.haml
= semantic_form_for resource, :url => registration_path(resource_name) do |f|
= f.inputs do
= f.input :email, :required => true
= f.input :password, :required => true
= f.input :password_confirmation, :required => true
= commit_button("Registrierung absenden")
但是现在有一个问题 - 我的页面上有两个字段具有相同的属性id:user_email
当我尝试用
填写注册表时# registration_steps.rb
When /^I fill in registration data$/ do |param|
# this one selects the wrong form - loginform instead of registration form
fill_in("user_email", :with => "blabla")
end
字段的属性ID相同,“fill_in”选择错误的输入...
如何更改id以使用设计?对我来说似乎太复杂了..
我是否正确地指出了我的问题?
的更新 的
这是我呈现的注册网站的一部分:
<html>
....
<!-- you see that both forms contain fields with the same ids! -->
<!-- so when i test f.e. with fill_in("user_login", :with => "123")
then the wrong form will be filled out! -->
<form accept-charset="UTF-8" action="/users/sign_in" method="post">
<input id="user_login" name="user[login]" size="30" type="text" />
<input id="user_password" name="user[password]" size="30" type="password" />
<input type="submit" value="anmelden" name="commit">
</form>
...
<form accept-charset="UTF-8" action="/users/sign_in" method="post">
<input id="user_login" name="user[login]" size="30" type="text" />
<input id="user_password" name="user[password]" size="30" type="password" />
<input type="submit" value="anmelden" name="commit">
</form>
...
</html>
答案 0 :(得分:0)
使用with_scope(“123”)解决了问题
with_scope("#user_new_form") do
fill_in("user_email", :with => "123")
end