Hi all,
In my project, users can recommend other users:
class User
has 0..n, :recommendations
has 0..n, :recommendees, :through => :recommendations, :class_name
=> "User", :child_key => [:user_id]
has 0..n, :recommended_by, :through => :recommendations, :class_name
=> "User", :child_key => [:recommendee_id], :remote_name => :user
end
class Recommendation
include DataMapper::Resource
property :user_id, Integer, :key => true
property :recommendee_id, Integer, :key => true
belongs_to :user, :child_key => [:user_id]
belongs_to :recommendee, :child_key =>
[:recommendee_id], :class_name => "User"
end
I created routes both for the recommendations standing in themselves
and when they are nested in the user resource:
(...)
resources :recommendations
resources :users do |users|
users.resources :recommendations
end
What I realized though is if I want to use controller actions for both
of these routes, it will make them too complicated to be
understandable/maintainable. For example, the "index" action of the
"recommendations" controller will be both called from a URL like "/
recommendations" and from "/users/1/recommendations".
Clearly, the data I should show in these two cases is different, so
the controller code should handle this somehow.
The "create" action in the controller is even messier, redirecting to
different URLs depending on where we came from, etc. These dual-duty
controllers will be bloated and not nice.
I suspect that this is not the way to go and I am very curious to find
out a/the correct way to handle this. Should I make an admin namespace
and copies of the controllers in the admin area? (admin user
controller, admin recommendation controller). Should I then route the
generated URLs for the resources to the admin controllers? (e.g '/
users to '/admin/users', '/recommendations/1/' to /admin/
recommendations/1', etc.) Or is there another way?
Thank you for your advice,
Balint
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---