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

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 => 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

On Thu, Jul 17, 2008 at 8:51 PM, Tarscher [email protected] wrote:

Thanks;
Stijn


Nibirutech CTO Eric.Archangel
MSN: [email protected]
QQ: 996252
GMAIL: [email protected]
BLOG: http://blog.sina.com.cn/gameloft

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs