[Radiant] custom controllers displaying a page from radiant

Alexander Horn alex.horn at gmail.com
Thu Oct 12 19:10:40 CDT 2006


> def index
>      @page = Page.find (1)
>      custom_content = render_partial 'some_partial'
>      @page.page_parts << PagePart.new( :name=>'form',
> :content=>custom_content )
>      process_page   # this is the part I really cant remember, it was three
> lines or so of code
> end

If I understand correctly you are trying to decompose your "behavior"
into a model, and a controller. I like the fact that you are thinking
outside the box. You are right. Certain things could be done more
easily in a controller.

As part of the "corex" branch, I have done a few experiments of
similar kinds: the goal is to create a separation of model and
controller logic.

Here are couple observations I have made:

A hypothetical SiteController#process_page() method may look so:

class SiteController < ApplicationController
  ...

  def process_page
    if @page.layout
      content_type = @page.layout.content_type.to_s.strip
      @response.headers['Content-Type'] = content_type unless
content_type.empty?
    end
    headers.each { |k,v| @response.headers[k] = v }
    @response.body = render
  end
  ...
end

It seems the biggest challenge with this approach is the coordination
of the dispatcher process. Consider a situation where someone would
like to overwrite this process_page() method in a subclass.

Example:

class MySiteController < SiteController
  def process_page
    ...
    super
  end
end

Now how does this MySiteController get called. Clearly we must first
find the page by the given url [ find_page_by_url() ] before we can
make the decision what controller would be appropriate to handle the
page request. That's a problem I am facing. I am not quite sure how to
solve the issue of finding the page (which is a model) and directing
the program flow to the controller (i.e. SiteController or a subclass
thereof).

Clearly, it would be beneficial to be able to write your own
controller. However, how does the dispatcher know which controller
goes with what page? .... I am still contemplating on this....

-- 
Alexander Horn
http://www2.truman.edu/~ah428



On 10/12/06, orff <proudestmonkey at gmail.com> wrote:
> I would love to just be able to call methods in my own custom controller to
> display the CMS content, but do things like form handling / database
> interaction using rails proper and not have to write behaviors to add
> functionality.  I have successfully written my own behavior based off of the
> mailer behavior to submit form data to a model, but the whole time what I
> really wanted to do was just display a certian page from the CMS with my own
> forms / validation / etc happening as rails code.
>
> I played around with a new controller on my dev version calling render with
> an injected page part, but could not get it to work without committing the
> page part to the database first.  I have since deleted it, but the code was
> similar to this (sorry, I dont have the exact code, but I think you can get
> the idea)
>
> def index
>      @page = Page.find (1)
>      custom_content = render_partial 'some_partial'
>      @page.page_parts << PagePart.new( :name=>'form',
> :content=>custom_content )
>      process_page   # this is the part I really cant remember, it was three
> lines or so of code
> end
>
> Is there anyone from the development team that could give me a hint as to
> how to do this, or convince me that custom controllers are a really bad idea
> and I should just write behaviors ?  I understand fully there are lots of
> things that can do wrong with modifying the page real-time, but it would be
> nice to just do my forms in rails with validations, activerecord
> relationships, etc. etc.
>
> Debugging behaviors is a real pain because I keep having to re-start my web
> server to see new results (even in development mode).  Maybe if someone can
> tell me how to fix just this problem I'd be a little more happy to write
> behaviors.
>
> -mike
>
>
> _______________________________________________
> Radiant mailing list
> Post:   Radiant at lists.radiantcms.org
> Search: http://radiantcms.org/mailing-list/search/
> Site:
> http://lists.radiantcms.org/mailman/listinfo/radiant
>
>



More information about the Radiant mailing list