Forum: Radiant CMS Can you use controllers/views within a tag

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
61c2e937e608b1a57b6c7f9468a9455c?d=identicon&s=25 jsmorris (Guest)
on 2007-02-04 18:46
(Received via mailing list)
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 << "<table>...</table>" 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
Dc893f8ae12045dc71048a0c6a56fc01?d=identicon&s=25 Jacob Burkhart (igotimac)
on 2007-02-05 03:10
Jason, can you clarify what you are trying to do a little more?  You
seem to be asking multiple questions at once.
61c2e937e608b1a57b6c7f9468a9455c?d=identicon&s=25 jsmorris (Guest)
on 2007-02-05 03:35
(Received via mailing list)
My question is...

Can a typical rails view (created under the extension in the
extension/app/view folder) be render from a radius tag?
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-02-05 06:02
(Received via mailing list)
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
78cb50691f1df8fd06c2cf26c524e598?d=identicon&s=25 Michael Jones (Guest)
on 2007-02-05 06:08
(Received via mailing list)
>   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...
1c1e3bdfe006a22214102fcd6434a012?d=identicon&s=25 Daniel Sheppard (Guest)
on 2007-02-05 08:02
(Received via mailing list)
> >   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.
61c2e937e608b1a57b6c7f9468a9455c?d=identicon&s=25 jsmorris (Guest)
on 2007-02-06 07:38
(Received via mailing list)
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:in
`const_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:in
`load_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:in
`new_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:in
`require_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:in `load'
        from /usr/local/bin/mongrel_rails:18


Thanks,
Jason
78cb50691f1df8fd06c2cf26c524e598?d=identicon&s=25 Michael Jones (Guest)
on 2007-09-25 23:06
(Received via mailing list)
Jason, did you ever get this to work?
61c2e937e608b1a57b6c7f9468a9455c?d=identicon&s=25 jsmorris (Guest)
on 2007-09-25 23:08
(Received via mailing list)
Unfortunately, I have pulled away from doing any more work on this,
but I hope to get back to this soon.
1c1e3bdfe006a22214102fcd6434a012?d=identicon&s=25 Daniel Sheppard (Guest)
on 2007-09-25 23:09
(Received via mailing list)
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).
This topic is locked and can not be replied to.