RailsCasts Pro episodes are now free!

Learn more or hide this

Dan Tappin's Profile

GitHub User: jasper502

Comments by Dan Tappin

Avatar

I am working on an app that has all the tenants data in one table. I am looking at segregating that for security reasons. My target market will have a range of security requiremnts - some won't care and will be fine with the shared set-up some would want something like Apartment and some perhaps extreme like a completly separate instance of the app on a subdomain or internally hosted.

Any suggestions on such a set-up? I am thinking I could have a 'basic' plan (shared db), a 'plus' plan (Apartment etc.) and a 'pro' plan (private server type setup). I have no real data but I would say the split would be 75%/20%/5%.

Is it worth the effort to maintain 3 versions of the same code base?

Avatar

I have a Locations model with an belongs to association to my Areas model. The Areas model is setup with the Ancestry gem where I can build an arbitrary hierarchy of 'Areas' Say like this:

Main Area 1(id = 1)
- Sub Area 1.1 (id = 2)
-- Child Area 1.1.1 (id = 3)
-- Child Area 1.1.2 (id = 4)
- Sub Area 2 (id = 5)
-- Child Area 2.1 (id = 6)
-- etc...

So in my Locations model I have a area_id column and it's easy enough to call Locations.find(1).area.name = 'Child Area 1.1.2' and I can sort easy enough on this.

Now I have also created methods using ancestry functions in the Locations model to return the parent area's like this:

Locations.find(1).area_level_1 = 'Main Area 1'
Locations.find(1).area_level_2 = 'Sub Area 1.1'
Locations.find(1).area_level_3 = 'Child Area 1.1.2'

It's a bit of a hack but work except I can't sort on it. If I call Locations.all I can loop through and display a table etc. on a view and can create a sort function on the last child (i.e. area.name) but sorting based on area_level_1 fails. I am guessing there is an ugly manual SQL way to do this but I was hoping to perhaps find a more elegant way.

Where is really gets ugly is I am trying to leave the structure open enough where the area_id could only be 1 or 2 levels deep (i.e. id = 1 or id = 2 in my example data).

Avatar

I am trying to implement the same thing. Here is my post on stackoverflow:

http://stackoverflow.com/questions/12496333/stange-behaviour-with-twitter-activerecord-reputation-system-average-rating

I tried to follow the same methodology as Ryan has here for the Haiku voting but I must be missing something on my structure.

The 'average' that I get back is not as expected and almost like the it's tracking the previous ratings.

Avatar

Ryan,

As mentioned above my resources are nested. I would suggest one change:

resource, id = request.path.split('/').last(2)

Avatar

I have been working on a similar system except that mine is more complex because i have nested resources. I can't get past the first level of nesting with the polymorphic path in the form_for.

For example I have something like this:

Locations with many Building with many Rooms. I want to comment on each with the polymorphic relationship but the system fails when you try to comment on a Building Rails throws an exception looking for 'building_comments_path' but the routing table generates 'location_building_comments_path'.

I am at a loss to generate the polymorphic path on the fly. I could manually generate the routes or the path in my controllers but I figure there has to be a better solution.