Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6595023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:53:10+00:00 2026-05-25T17:53:10+00:00

Let’s say you have a resource called Article. On the index page, you have

  • 0

Let’s say you have a resource called Article. On the index page, you have many articles listed. In one scenario, I have this Cucumber step:

When /^I activate the edit article switch for the article "(.+)"$/ do |name|

I’m trying to identify that specific article – i.e. clicking the “edit” button for that specific article. I’ve been thinking about using the “within” helper of capybara, but I don’t feel like that’s the solution. I somehow need to find the name of the article on the page and then click that article’s particular edit button… see what I mean?

If anyone has a clean solution, I’d appreciate knowing it. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:53:11+00:00Added an answer on May 25, 2026 at 5:53 pm

    What I do for this kind of thing is write a step like this:

    When I edit article "Some article name or id"
    

    My step definition then looks like this:

    When %|I edit article "$article_name"| do |article_name|
      article = Article.find_by_name(article_name)
      within "#article_#{article.id}" do
        #do whatever you need to do for that article
        click "Edit"
      end
    end
    

    In my views I’m clearly defining the id on some parent element that will sufficiently scope calls like this. This pattern keeps you from having to get too dirty in the cukes themselves, while still giving you a certain degree of flexibility. For example:

    <% @articles.each do |article| %>
      <div id="article_<%= article.id %>">
         Stuff in here <%= link_to "Edit", edit_article_path(article) %>
      </div>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have a C++ Visual Studio 2010 solution with 2 projects: one
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I'm loading a page that contains this code: <script> function functionAlert() {
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have an image called hello.png with dimensions 200x100 . I create
Let's say I don't have photoshop, but I want to make pattern files (.pat)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.