# Can I replace all link\_to() with link\_if\_authorized()?

**URL:** <https://www.ruby-forum.com/t/can-i-replace-all-link-to-with-link-if-authorized/95072>\
**Category:** Engines\
**Created:** [May 21, 2006, 3:06pm UTC](https://www.ruby-forum.com/t/can-i-replace-all-link-to-with-link-if-authorized/95072 "2006-05-21T15:06:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [May 21, 2006, 3:06pm UTC](https://www.ruby-forum.com/t/can-i-replace-all-link-to-with-link-if-authorized/95072/1 "2006-05-21T15:06:53Z")

</div>

Hi all

I’m working with the UserEngine and now I’m wondering, if I can use  
link\_if\_authorized() everywhere I’m using link\_to() at the moment…?

If so, I could only overwrite the link\_to method like the following,  
right?

Something::SomethingElse  
link\_to(controller, action)  
link\_if\_authorized(controller, action)  
end  
end

Thanks for help! 🙂  
Joshua

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [May 21, 2006, 11:39pm UTC](https://www.ruby-forum.com/t/can-i-replace-all-link-to-with-link-if-authorized/95072/2 "2006-05-21T23:39:19Z")

</div>

It’s probably a bad idea to flat-out override link\_to, since there  
will be occasions that you don’t want to check authorisation when  
creating a link. It’s worth noting that each call to  
link\_if\_authorized creates a call to authorized?(), which in turn asks  
the DB about the current users permissions - having EVERY link in your  
site do this is going to impact performance at some point [1].

Instead, I’d suggest that you use link\_if\_authorized only when it is  
truly appropriate to do so.

- james

[1] future versions might address this in some way, although I  
wouldn’t rely on that happening.
