# How to use restful\_authentication for nested resources in Ra

**URL:** <https://www.ruby-forum.com/t/how-to-use-restful-authentication-for-nested-resources-in-ra/193478>\
**Category:** Rails\
**Created:** [August 18, 2010, 1:28pm UTC](https://www.ruby-forum.com/t/how-to-use-restful-authentication-for-nested-resources-in-ra/193478 "2010-08-18T13:28:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 18, 2010, 1:28pm UTC](https://www.ruby-forum.com/t/how-to-use-restful-authentication-for-nested-resources-in-ra/193478/1 "2010-08-18T13:28:52Z")

</div>

I have a nested resource hotel\_user and i wish to have  
hotel\_users\_controller under hotel namespace.

I want to use restful authentication here and I want  
hotel\_users\_controller, sessions\_controller in hotel directory like  
hotel/hotel\_users\_controller and hotel/sessions\_controller. I tried with  
the following command in terminal and it failed.

script/generate authenticated hotel\_user hotel/session

and it failed with the error

The name ‘AuthenticatedSystem’ is either already used in your  
application or reserved by Ruby on Rails.Please choose an alternative  
and run this generator again.

The authenticated\_system.rb file exists for some other resource under  
lib directory and not for hotel\_user. the generator is seeing it and  
fails the generation of files. what can I do? please help

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 18, 2010, 3:49pm UTC](https://www.ruby-forum.com/t/how-to-use-restful-authentication-for-nested-resources-in-ra/193478/2 "2010-08-18T15:49:48Z")

</div>

lucky in ruby wrote:

> I have a nested resource hotel\_user and i wish to have  
> hotel\_users\_controller under hotel namespace.
> 
> I want to use restful authentication here  
> […]

No you don’t. restful\_authentication should never be used: it relies  
too much on unmaintainable generated code that takes over your User  
model. It was OK when better alternatives didn’t exist, but they do  
now. Use Authlogic or something else reasonable.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 18, 2010, 4:11pm UTC](https://www.ruby-forum.com/t/how-to-use-restful-authentication-for-nested-resources-in-ra/193478/3 "2010-08-18T16:11:04Z")

</div>

Marnen Laibow-Koser wrote:

> lucky in ruby wrote:
> 
> > I have a nested resource hotel\_user and i wish to have  
> > hotel\_users\_controller under hotel namespace.
> > 
> > I want to use restful authentication here  
> > […]
> 
> No you don’t. restful\_authentication should never be used: it relies  
> too much on unmaintainable generated code that takes over your User  
> model. It was OK when better alternatives didn’t exist, but they do  
> now. Use Authlogic or something else reasonable.

Besides your choice of authentication systems, it also sounds to me like  
you may be confusing authentication and authorization. If you want to  
add some sort of role based authorization then take a look at one of the  
authorization gems/plugins such as CanCan.

> **[GitHub - ryanb/cancan: Authorization Gem for Ruby on Rails.](https://github.com/ryanb/cancan)**
>
> Authorization Gem for Ruby on Rails. Contribute to ryanb/cancan development by creating an account on GitHub.

I could be misunderstanding your needs. If so then just ignore this  
comment.

---

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [August 18, 2010, 5:16pm UTC](https://www.ruby-forum.com/t/how-to-use-restful-authentication-for-nested-resources-in-ra/193478/4 "2010-08-18T17:16:22Z")

</div>

Marnen Laibow-Koser wrote:

> lucky in ruby wrote:
> 
> > I have a nested resource hotel\_user and i wish to have  
> > hotel\_users\_controller under hotel namespace.
> > 
> > I want to use restful authentication here  
> > […]
> 
> No you don’t. restful\_authentication should never be used: it relies  
> too much on unmaintainable generated code that takes over your User  
> model. It was OK when better alternatives didn’t exist, but they do  
> now. Use Authlogic or something else reasonable.
> 
> ## Best,
> 
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

Thank you. I will use authlogic. I have just entered rails horizon and  
thank you so much for the recommendation.
