For security reasons, we have a requirement to skip loading ActiveRecord during the initialization of a rails 3 application. We know that could be done using the approach described in here. However, in some point after, we need to call an ActiveRecord model, hence, initialize ActiveRecord at that point and call ActiveRecord::Base.establish_connection
. How can we activate ActiveRecord in the middle of the application's lifecycle?
Asked
Active
Viewed 198 times
1

Community
- 1
- 1

AsemRadhwi
- 887
- 11
- 21
-
1When are you allowed to `ActiveRecord`? And what's the exact security statement? – Reactormonk Dec 18 '11 at 14:41
-
Every authenticated user is a standalone user in the database. All database connections should be based on the user's credentials. Hence, `ActiveRecord` will kick in after the user logs in, not when the application is initialized. – AsemRadhwi Dec 18 '11 at 14:49
-
`ActiveRecord` needs table structure information for reflection. So you'd have to give AR its own user for that, so it can query these. Or do you want to use the credentials of the first user for that? – Reactormonk Dec 18 '11 at 14:55
-
Actually that's not an issue because we are using public synonyms for each table. So, yes, any user will be adequate to perform the reflection that `ActiveRecord` is looking for. – AsemRadhwi Dec 18 '11 at 15:13
-
So one connection per user logged in, with that users credentials? – Reactormonk Dec 18 '11 at 15:20
-
Precisely, every user with her own connection. I know that can be achieved using `:before_filter` and call `ActiveRecord::Base.establish_connection`, passing the user's credentials. Now, the challenge is how to disable `ActiveRecord` during initialization and then re-enable it again right after the user is authenticated, before calling the `establish_connection` method. – AsemRadhwi Dec 18 '11 at 15:26
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5959/discussion-between-tass-and-asemradhwi) – Reactormonk Dec 18 '11 at 15:29