# Basic Authentication

**URL:** <https://www.ruby-forum.com/t/basic-authentication/105445>\
**Category:** Rails\
**Created:** [May 30, 2007, 1:34am UTC](https://www.ruby-forum.com/t/basic-authentication/105445 "2007-05-30T01:34:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![david\_salisbury](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@david\_salisbury](https://www.ruby-forum.com/u/david_salisbury)\
**Post date:** [May 30, 2007, 1:34am UTC](https://www.ruby-forum.com/t/basic-authentication/105445/1 "2007-05-30T01:34:12Z")

</div>

I’m trying to blend an old ( and I mean old 🙂 legacy system with a new  
rails side. The old system used basic authentication, and in attempting  
to create a seamless integration between the two, rails will need to use  
basic authentication also. Problem is, we’re not just wanting to  
protect a few pages, but if they’ve logged in to carry that state around  
with the pages. With basic authentication, the only way to do this is  
by using ( adjusting ) the url. So we need to have two urls to the same  
page, but one will check for authentication and one wont.

Since in rails a different url means a different method, right now ( and  
I hate to do this and will look into all suggestions you guys might  
have! ) I have two methods for each rails page, each rendering the same  
view, one is protected and one isn’t. But what I need is a way for the  
view to know which method called it, and based on that to adjust any  
link\_to’es accordingly. So I might have a “list” method, and an “rlist”  
method, and the view would need to see that “rlist” called it and adjust  
it’s links to say “redit” and “rshow” instead of “edit” and “show”.

If there’s a routes.rb solution which could get rid of the dual methods  
I’m _all_ ears, but seems the view is still going to need to detect  
which method called it.

Thanks for any ideas and info!! Oh yea… and I’m using a plugin for the  
basic authentication in rails.

-Dave

---

<div class="post-metadata">

**Author:** ![david\_salisbury](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@david\_salisbury](https://www.ruby-forum.com/u/david_salisbury)\
**Post date:** [June 1, 2007, 3:10pm UTC](https://www.ruby-forum.com/t/basic-authentication/105445/2 "2007-06-01T15:10:09Z")

</div>

What I would do is this: write a method in application\_helper.rb called  
my\_link\_to which calls link\_to with the appropriate parameters depending  
on the name of the action (which you can examine in  
self.controller.action\_name).

Something like this might work:

def my\_link\_to(name, options = {}, html\_options = nil,  
\*parameters\_for\_method\_reference)  
if self.controller.action\_name =~ /^r/  
link\_to(‘r’ + name, options, html\_options,  
parameters\_for\_method\_reference)  
else  
link\_to(name, options, html\_options,  
parameters\_for\_method\_reference)  
end  
end

The replace your link\_to calls in the view with my\_link\_to.

steve
