# 2 views, 1 action

**URL:** <https://www.ruby-forum.com/t/2-views-1-action/143337>\
**Category:** Rails\
**Created:** [July 17, 2008, 2:51pm UTC](https://www.ruby-forum.com/t/2-views-1-action/143337 "2008-07-17T14:51:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [July 17, 2008, 2:51pm UTC](https://www.ruby-forum.com/t/2-views-1-action/143337/1 "2008-07-17T14:51:59Z")

</div>

hi all,

I want to have an index view for photoalbums both for an admin and for  
the users. Does Rails provide a better way to do something like  
[site.com/albums?admin=1](http://site.com/albums?admin=1) =\> shows admin index and [site.com/albums](http://site.com/albums) =\>  
shows indew for users  
Where i would do something like if params[:admin] == 1 (and some  
session checking also) to make the difference between the 2 views?

Thanks;  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [July 17, 2008, 2:56pm UTC](https://www.ruby-forum.com/t/2-views-1-action/143337/2 "2008-07-17T14:56:06Z")

</div>

On 17 Jul 2008, at 13:51, Tarscher wrote:

> hi all,
> 
> I want to have an index view for photoalbums both for an admin and for  
> the users. Does Rails provide a better way to do something like  
> [site.com/albums?admin=1](http://site.com/albums?admin=1) =\> shows admin index and [site.com/albums](http://site.com/albums) =\>  
> shows indew for users  
> Where i would do something like if params[:admin] == 1 (and some  
> session checking also) to make the difference between the 2 views?

Well you can call render :action =\> whatever you want at any point in  
your action.

Fred

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [July 17, 2008, 2:56pm UTC](https://www.ruby-forum.com/t/2-views-1-action/143337/3 "2008-07-17T14:56:42Z")

</div>

I would recommend namespacing this and having two separate views AND  
two separate actions. Sometimes you may want to do something on the  
admin side that you don’t want to do on the user side.

I wrote a tutorial on this back in March:

> **[frozenplague.net](http://frozenplague.net/2008/03/16/administration-namespacing/)**
>
> This domain may be for sale!

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [July 17, 2008, 3:37pm UTC](https://www.ruby-forum.com/t/2-views-1-action/143337/4 "2008-07-17T15:37:14Z")

</div>

It is not difficult

supposed your [site.com/albums](http://site.com/albums) is handled by AlbumsController’s index  
action,  
then you can

edit albumscontroller.rb 's index method as followings

def index  
redirect\_to “/admin/index” and return if params[:admin] == “1”  
// … here is normal dealings  
end

On Thu, Jul 17, 2008 at 8:51 PM, Tarscher [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks;  
> Stijn
> 
> >

–  
Nibirutech CTO Eric.Archangel  
MSN: removed\_email\_address@domain.invalid  
QQ: 996252  
GMAIL: removed\_email\_address@domain.invalid  
BLOG: [http://blog.sina.com.cn/gameloft](http://blog.sina.com.cn/gameloft)

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [July 18, 2008, 5:55am UTC](https://www.ruby-forum.com/t/2-views-1-action/143337/5 "2008-07-18T05:55:05Z")

</div>

Eric,

What’s stopping somebody from then specifying ?admin=1 on the end of  
the URL and gaining access to those protected actions?

Using a login system with a field identifying a user as an admin or  
not has much greater security than simply something that could be  
tampered with by a script kiddie.

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [July 18, 2008, 1:04pm UTC](https://www.ruby-forum.com/t/2-views-1-action/143337/6 "2008-07-18T13:04:50Z")

</div>

Great tutorial,

This wasexactly what I’m was looking for

Thanks
