2 views, 1 action

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 => shows admin index and 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

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 => shows admin index and 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

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: http://frozenplague.net/2008/03/16/administration-namespacing/

It is not difficult

supposed your 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

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.

Great tutorial,

This wasexactly what I'm was looking for

Thanks