Trying to use the "smart" API for link_to
def create_link(object, label = nil) label ||= auth_labels[:new] link = link_to(label, [:new, object]) if can?(:create, object) link.sub /new\./, 'new/' end
But this generates a link like /projects/new.1 , instead of /projects/ new I would assume it would make sense to pass it the class instead, like this, sense in this case the class itself should carry enough information to generate the path?
def create_link(object, label = nil) label ||= auth_labels[:new] link = link_to(label, [:new, object.class]) if can?(:create, object) end
But then I get:
undefined method `new_projects_path' for #<#<Class:0x000001017f0ad8>: 0x000001017eebe8>
If I substitute the key with :create it tries with create_projects_path which doesn't exist.
What am I doing wrong here? Or is it a bug in edge rails?