Using Rails app within radiant

Hi,

I have radiant running my website and would like to use some models
and functions from another rails app running in the same server. Any
ideas on how to do this if its possible?

Thanks in advance,

jorge.

Jorge,

If your app is ActiveResource-compatible, that might be an easy way to
integrate them.

Sean

Well, my rails app it’s a bit old, so it’s not
ActiveResource-compatible. It would be great though, to rewrite it and
make it RESTful in the future, but currently I don’t have the time. Is
there another way to achieve what I’m looking for?

Thanks,

Jorge.

You could import some of your models into a Radiant extension and then
use them there. They may have to connect to your other database
manually, i.e. inside their declaration.

Sean

Hi Sean,

I’ve explored further this approach and it looks exactly what I’m
looking for, but I’m having problems loading the AR models into
Radiant.

I created the extension and the custom tags, (pretty easy and slick
indeed :), and put the require environment.rb of my rails app at the
top of the
‘radiantsite/vendor/extensions/myextension/lib/myextension.rb’
file but I got this errors:

warning: already initialized constant OPTIONS
/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:18:
undefined method `options’ for []:Array (NoMethodError)

and the radiant’s mongrel server doesn’t boot anymore.

Do I need to require the environment.rb file somewhere else or is
there other method to load my app’s models into the radiant.

Thanks in advance!

jorge.

I’ve copied my rails app environment.rb customizations to the radiant
project’s environment.rb and it’s now it’s loading ok, but still my
models are not yet accesible from radiant. I’m using
ActiveRecord::Base.establish_conection in the extension’s activate
method to connect to the rails db, but I don’t know how to load my
rails model definitions. Could you please give me some details on how
to do it? Sorry if it’s something obvius but I’m really lost here.

Thanks a lot for your help,

Jorge

Jorge,

You shouldn’t require the environment.rb of your Rails app directly.
Copy any customizations you have made either into your Radiant
project’s environment.rb or into the activate method of your
extension. Hopefully that should fix the issue.

Sean

As long as they are in app/models or lib/ of your extension, they
should be accessible; that is, they will be in the load path. How you
integrate them into the Radiant application is another story… you
may need to create some controllers and views, or maybe some Radius
tags. Both of those are briefly covered in the extension tutorial on
the wiki.

Sean