Hi Alex
On Dec 22, 2:50 am, Alexander Hoth <
m...@alexanderhoth.com> wrote:
> Is there any way with rc to accomplish something like the /account pattern
> for the currently logged in user with subdomains instead?
>
> Normally we would map everything under a specific account like that:
>
> map_enclosing_resource :account, :singleton => true, :find =>
> :current_account
>
> This works fine with
>
http://www.example.com/account/items
> But what would I need to do for the same funktionality with an url like
> that?
>
http://foo.example.com/items
To get
http://foo.examples.com/items to work I think (i've not tried
it) you'll need to override the RC resource_service (which in turn is
used by find_resource, find_resources, and new_resource) in a before
filter in your items_controller.
before_filter :set_resource_service
def set_resource_service
@account = ....... # set @account based on subdomain
resource_service = @account.items
end
(This code uses this method:
http://plugins.ardes.com/doc/resources_controller/classes/Ardes/ResourcesController/InstanceMethods.html#M000025
)
While this works for your /items controller you'll also need to set up
a map_enclosing_resource :item for any nested controllers (e.g.
foo.example.com/items/4/picture ,
foo.example.com/items/4/comments/3 )
to correctly find @item (e.g. @account.items.find(4) ) otherwise RC
won't scope correctly (e.g. Item.find(4) ).
You'll need to repeat all of this for any other top level and nested
resources under
foo.example.com.
My thoughts are that if your users need to be logged in do you really
care what segments appear in the url? Also if you're scoping to to
the logged in user I prefer to use a top level singleton resource
called /user , that way RC sets automatically sets the instance
variable @user correctly. If you're using /account you end up with
@account instance variable being set to your current User
( Alternatively, using /account does makes sense if you have an
Account model instance to match up to the current_user or
subdomain ). If
foo.example.com is a public site it's easier to use
RC with normal /account pattern but you can make the leading singular-
resource/routing-segment to be something more preferable such as /
bookshelf , /catalogue , /portfolio , /our, /my etc. or you can even
use multiple differently named /account(s) (that behave identically)
if you need them for usability or SEO purposes.
Jason.