Can you use controllers/views within a tag

Using radiant (mental), I have created my extension and have the
model/view/controller working from within the admin page layout with
no problems. I can create/list/edit/destroy my model instances.

Now, I want to list each instance of my model from within a page on
the website using a radius tag <r:mytag /> and the website layout. I
believe using a tag would be the most appropriate.

As I have tried so far, I have recreated the view from within my tag
using the content << “

” method. It seems that there
should be a better way so that I don’t repeat myself by creating two
views, one for the admin page and the second for the radius tag.

Is there a way to reuse the view/controller inside the radius tag?
Maybe something like

module MyTag
include Radiant::Taggable

desc %{ <r:mytag />

Displays the list of mytag available. }
tag “mytag” do |tag|
render(:controller => MyController, :action => MyAction)
end
end

or something to that effect.

I would also like to render the form so that users can input models on
my site as well. I just thought that I would try the list first.

Very new to all of this, so any pointers or directions would be much
appreciated.

Jason

Jason, can you clarify what you are trying to do a little more? You
seem to be asking multiple questions at once.

My question is…

Can a typical rails view (created under the extension in the
extension/app/view folder) be render from a radius tag?

Short answer: no. Long answer: maybe, but it could get ugly. Although
maybe what you’re trying to do doesn’t really need a traditional Rails
view template, but a collection of tags and a snippet? Let us know more
of what you want to do.

Sean

Displays the list of mytag available. }
tag “mytag” do |tag|
render(:controller => MyController, :action => MyAction)
end

I wish it was this easy.

I look forward to the discussion of how best to do this sort of thing…

Displays the list of mytag available. }
tag “mytag” do |tag|
render(:controller => MyController, :action => MyAction)
end

I wish it was this easy.

This is just off the top of my head but:

class EasyControllerExtension

def activate
class << SiteController
def show_uncached_page(url)
@page = find_page(url)
unless @page.nil?
@page.process_controller(self)
@cache.cache_response(url, response) if live? and @page.cache?
@performed_render = true
else
render :template => ‘site/not_found’, :status => 404
end
rescue Page::MissingRootPageError
redirect_to welcome_url
end
end
class << Page
attr_accessor :controller
def process_controller(controller)
@controller = controller
process(controller.request, controller.response)
end
end
end
end

Then you should be able to just do:

tag “mytag” do |tag|
tag.globals.page.controller.render(:partial => ‘monkeys’)
end

Dan.

Jason, did you ever get this to work?

I tried to implement your suggestion here, but I was not successful.
I am not sure I follow what this code is doing…but I am still
learning ruby.

I attached my attempt. Maybe you or some else can see what is wrong.

This was the error I was getting

/Users/jsmorris/sprout/aztracc/config/…/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:267:in
load_missing_constant': uninitialized constant ApplicationController (NameError) from /Users/jsmorris/sprout/aztracc/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:453:inconst_missing’
from
/Users/jsmorris/sprout/aztracc/config/…/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:465:in
const_missing' from /Users/jsmorris/sprout/aztracc/config/../app/controllers/site_controller.rb:1 from /Users/jsmorris/sprout/aztracc/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:204:inload_without_new_constant_marking’
from
/Users/jsmorris/sprout/aztracc/config/…/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:204:in
load_file' from /Users/jsmorris/sprout/aztracc/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:343:innew_constants_in’
from
/Users/jsmorris/sprout/aztracc/config/…/vendor/rails/activerecord/lib/…/…/activesupport/lib/active_support/dependencies.rb:203:in
load_file' from /Users/jsmorris/sprout/aztracc/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:95:inrequire_or_load’
… 29 levels…
from
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in
run' from /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 from /usr/local/bin/mongrel_rails:18:inload’
from /usr/local/bin/mongrel_rails:18

Thanks,
Jason

Oh, you need to explicitely require ‘application’ to load the
application controller - The application controller is not loaded until
after the extensions, which means that any reference to a controller
will be unable to load it’s superclass (as the class is named
ApplicationController, but it is loaded from an application.rb file - a
default I’ve never understood about rails, but I’m guessing it served a
historical purpose).

Unfortunately, I have pulled away from doing any more work on this,
but I hope to get back to this soon.