开发者

Setting Active Resource site dynamically at runtime

开发者 https://www.devze.com 2023-04-04 15:10 出处:网络
I am stuck on how to set the site variable to ActiveResource at runtime, I read this post which explains how to do the same

I am stuck on how to set the site variable to ActiveResource at runtime, I read this post which explains how to do the same

http://blog.rubybestpractices.com/posts/gregory/rails_modularity_1.html

But the only problem there is the mapping from service name to url is predefined. I开发者_如何转开发n my case its the same service except in different domain and return identical results.

domain1.mydomain.com
domain2.mydomain.com

This active resource belongs to another active record model and which domain to access depends on the attributes active record model retrieves from database. Is there a way to do this?

Thanks in advance.


Surprisingly, it's pretty simple:

klass.site = "http://domain.com"
#make request
klass.site = "http://domain2.com
0

精彩评论

暂无评论...
验证码 换一张
取 消