【问题标题】:nested forms with capybara带有水豚的嵌套形式
【发布时间】:2014-05-26 23:16:54
【问题描述】:

我有一个帖子模型

    accepts_nested_attributes_for :views, :allow_destroy => :true,
      :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }

还有一个视图模型

    belongs_to :post, inverse_of: :views

在帖子/_forms.html.erb中

    <%= post_form.fields_for :views do |builder| %>
    <%= render 'view_fields', f: builder %>
    <% end %>
    <%= link_to_add_fields "Add new View", post_form, :views %>

在帖子/_view_fields.html.erb 中

    <fieldset>
    <%= f.label :name, "View name:" %>
    <%= f.text_field :name %>
    <%= f.hidden_field :_destroy %>
    <%= link_to "remove", '#', class: "remove_fields" %>
    </fieldset>

现在在我的 rspec 中,我想用一些值填充 f.text_field。

尝试了以下方法:

  fill_in 'post_views_first_name', with: "I support"
  fill_in 'post_view_name', with: "I support"
  fill_in 'post_views_name', with: "I support"

它们都不起作用。如何在该字段上调用 ​​fill_in?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 rspec capybara


    【解决方案1】:

    我正在使用水豚截图 gem(我强烈建议!)。我有一个嵌套表单,其中包含属于用户的项目。它接受

    fill_in 'user_projects_attributes_0_name', with: "Name"

    所以对你来说,我建议一定要抓住宝石。但也试试这个:

    fill_in 'post_views_attributes_0_first_name', with: "I support"

    【讨论】:

      猜你喜欢
      • 2011-09-26
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      相关资源
      最近更新 更多