Forum: Ruby on Rails Ambiguous match, found 5 elements matching link "BugSmash"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2017-03-03 14:55
Hi i am doing rspec testing now, Basically the test is allow navigating
from detail page to listing page, this part it passes, but when it comes
to listing page to detail page, it keep showing me this Ambiguous match,
found 5 elements matching link "BugSmash", and there's a error at this
Failure/Error: click_link event.name

my spec is located at rspec spec/features/navigate_events_spec.rb




routes.rb
-----------------------------------------------------------------
Rails.application.routes.draw do
  get "events" => "events#index"
  get "events/:id" => "events#show", as: "event"
end
------------------------------------------------------------------




nagivate_events_spec.rb
-------------------------------------------------------------------
require  "rails_helper"

describe "Navigating events" do

it "Allow nagivation from the detail page to the listing page" do

event = Event.create(name:"BugSmash",
                   location:"Denver",
                   price:10.00,
                   description:"A fun evening of bug smashing!",
                     starts_at: 10.days.from_now)

visit event_url(event)

click_link "All Events"

expect(current_path).to eq(events_path)


end




it "Allow nagivation from the listing page to the detail page" do

event = Event.create(name:"BugSmash",
                   location:"Denver",
                   price:10.00,
                   description:"A fun evening of bug smashing!",
                     starts_at: 10.days.from_now)

visit events_url

click_link event.name

expect(current_path).to eq(event_path(event))


end

end
-------------------------------------------------------------------


index.html.erb
------------------------------------------------------------------
<h1><%= pluralize(@events.size,"Event") %></h1>
<% @events.each do |event| %>

  <article>
   <header>
     <h2><%= link_to(event.name,event) %></h2>
   </header>
 <p>
       <%= truncate(event.description,length:35,separator: " ") %>
   </p>

    <table>
       <tr>
          <th>When</th>
          <td><%= event.starts_at %></td>
       </tr>

        <tr>
          <th>Where</th>
          <td><%= event.location %></td>
       </tr>

        <tr>
          <th>Price</th>
          <td><%= number_to_currency(event.price) %></td>
       </tr>
    </table>
  </article>

<% end %>
------------------------------------------------------------------
This topic is locked and can not be replied to.