Account Scoping

0 views
Skip to first unread message

tispratik

unread,
Dec 24, 2009, 1:12:53 PM12/24/09
to Saint Louis Ruby Users Group
Hi,

I want to implement account scoping in my application like in twitter
www.twitter.com/tispratik/events/1
meaning whatever am browsing in twitter, the route should contain
www.twitter.com/tispratik always.
or other users it should be www.twitter.com/user1 or www.twitter.com/user2
and so on...

Any ideas on how to write the routes.rb for this and how to use these
routes in controllers or views.

Thanks,
Pratik

tispratik

unread,
Dec 24, 2009, 1:17:24 PM12/24/09
to Saint Louis Ruby Users Group
Also in the controller i want to be able to retrieve the account name
as in params[:account_name]

so that i can do the necessary scoping while loading www.twitter.com/tispratik/events

tispratik

unread,
Dec 24, 2009, 1:41:05 PM12/24/09
to Saint Louis Ruby Users Group
map.resources :users, :path_prefix => ':account', :has_many
=> :contacts

worked for me. Once the user logs in, i find out the account info and
store it in the session.

Route i used: redirect_to user_path("tispratik",
@user_session.user.id)

which generated http://localhost:3000/tispratik/users/1

I could retrieve it as: logger.info("ACCOUNT: " + params
[:account].to_s)

Now how do i make sure that i dont have to put the account object
everytime i write a route?

meaning: Instead of writing, redirect_to user_path("tispratik",
@user_session.user.id)
i should write edirect_to user_path
(@user_session.user.id) without caring for the account each time, it
should be automatically added as a part of the route.


Thanks,
Pratik

Reply all
Reply to author
Forward
0 new messages