For a permissions system i'm writing i'm extending the standard link_to
helpers to check if a user has a permission to perform that action
before displaying a link to clean-up my code so i don't have to put if
checks all over them.
good to see that someone is trying to achieve EXACTLY the same thing
like me. I have even tried to dig deep in the link_to implementation to
solve this, but it is more than black magic and I soon gave up. Do you
have any new ideas regarding the problem?
Here's the implementation i ended up with. Its not very clean but it
does the job.
[code] def link_to(*args, &block)
unless params[:controller] =~ /admin/
super
else
if args.size > 2
super if action_allowed(args[1], args[2]["method"])
else
super if action_allowed(args[1])
end
end
end
def link_to_remote(name, options = {}, html_options = nil)
unless params[:controller] =~ /admin/
super
else
super if action_allowed(options[:url], options[:method])
end
end