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 3481114
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:24:57+00:00 2026-05-18T10:24:57+00:00

I’m using Cancan to control User abilities, and have recently run into an odd

  • 0

I’m using Cancan to control User abilities, and have recently run into an odd issue: my partial has a “destroy” hyperlink that shows up only sometimes for authorized users. When I refresh the page, there’s no telling whether the link will exist or not.

I’ve defined abilities for my Event model in Ability.rb in the following way:

can [:create, :update, :destroy], Event do |event|
    user.regattas(true).include?(event.regatta)
end

I use regattas(true) to prevent the system from using the cached associations, in case something’s changed recently.

In my rspec tests, this works great for the current user, both in my tests for Ability.rb and my EventsController tests.

Here’s the destroy. destroy hyperlink in my _event.html.erb partial, that I only want to appear when the user has the ability to destroy event:

<% if can? :destroy, event %>
  <td><%= link_to 'Destroy', event, :confirm => 'Are you sure?', :method => :delete %></td>
<% end %>

Any advice for how fix the flickering, and get the “Destroy” link to ALWAYS show up for authorized users? Has anyone else run into this issue?

More background: I don’t have this issue for another piece of code, not in a partial, shown here:

<% if can? :update, @regatta %>
    <%= link_to 'Edit Regatta Info', edit_regatta_path(@regatta) %> |
<% end %>

Thanks, all.

  • 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-18T10:24:57+00:00Added an answer on May 18, 2026 at 10:24 am

    Ryan Bates actually answered this one for me, on this cancan github issue. Looks like Cancan has a known issue with models using default_scope, documented on this ticket. In my case, event.rb included a call to default_scope. Taking that line out completely fixed the issue.

    The discussion on the second ticket indicated that this was an issue with Ruby on Rails, as discussed in this lighthouse ticket.

    Hope this helps anyone else with this strange issue! Thanks, Ryan… I’ll switch the answer over to you, if you happen to post on this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.