Rails disable eager loading for specific model -
i'm writing rails application functionality interfaces third-party api (streamsend) via activeresource. i'm using shopify's fork of activeresource thread-safe operation because different users of application have own streamsend api client id's , secret keys , don't want app step on them when interfacing third-party api.
i have in controller associated around_action filter:
private # set streamsend credentials in every request def set_ss_credentials streamsend.site, streamsend.user, streamsend.password = current_user_credentials yield ensure streamsend.site = streamsend.user = streamsend.password = nil end default_site, default_user, default_password = [ rails.application.secrets.streamsend_api_endpoint, "username", "password" ] def current_user_credentials current_user.present? ? [ rails.application.secrets.streamsend_api_endpoint, current_user.ss_userid, current_user.ss_key ] : [ default_site, default_user, default_password ] end and in model:
class streamsend < activeresource::base self.format = :xml def self.audience @audience ||= streamsend::audience.find(:first) end end the site , credentials meant fed in via controller action , current user that's logged in.
this works fine when using webrick, because default setting rails in production mode config.eager_load = true, application won't start because actual model lacking site , credentials well.
is there way can tell eager_load ignore ares-dependent models eager load actual database models?
the errors when launching in production mode came this:
def self.audience @audience ||= streamsend::audience.find(:first) end hard coding audience 1 default allowed me launch application in production mode. fine because streamsend supports 1 audience per account.
Comments
Post a Comment