ryanb/cancan — Issue #519: can?(new_customer_path)
Author: michelgrootjans
Created: 2011-11-25 15:02:40+00:00
State: open

Instead of having to write something like

``` ruby
def create_link(object, content = "New")
if can?(:create, object)
object_class = (object.kind_of?(Class) ? object : object.class)
link_to(content, [:new, object_class.name.underscore.to_sym])
end
end
```

Would it be possible to have a helper that looks at the url and deciedes based on the current routing authorization if the link can be shown or not.
Something along the lines of:

customers/index.html.erb:

``` ruby
<%= safe_link_to "Customers", new_customer_path, class: "btn" %>
```

customer_helper.rb:

``` ruby
def safe_link_to(*args, &block)
link_to(*args, &block) if can?(get_url_from(args))
end
```