What id like to do is call my controller directly using routes (or default routes), then render the page by calling radiant classes / methods. The radiant page dispatcher would not even come into play until after the custom controller runs (if I understand you correctly).
In other words URL ://mysite.com/contact
would call the radiant page controller and render the page, but
//mysite/forms/contact
would call my forms controller and render the page using the radiant layout of choice and then render and forms I decide in my controller by passing in partial(s).
//mysite/forms/contact_create
would use my rails code to create the contact entry in the model, then could redirect back to a radiant page
with the confirmation details
my forms controller would handle the interaction with the models, do the validation, etc. In my perfect world, all I need from the radiant code is way to display a page with a custom partial, see the contact_create method below:
class FormsController < ApplicationController
def index
contact_new
end
def contact_new
@page = Page.find_by_url ('contact/form_holder_page') # this is a hidden radiant page ??
custom_content = render_partial ('contact_form') # this form has a placeholder to display validation errors
@page.render_with_custom_page_part( :page_part => custom_content ) # this would be brilliant!! :-)
end
def contact_create
@contact = Contact.new( params[:contact] )
if @contact.save
flash[:notice] = 'Contact info info saved.'
redirect_to '/contact/thanks'
else
flash[:error] = 'Contact info could not be saved.'
render :action ="" 'contact_new'
end
end
end
thanks for the swift reply. I am on vacation next week, but then I look forward to installing and checking out the corex branch, I like where it is going ..
Mr out of the box, Mike
On 10/12/06, Alexander Horn <[EMAIL PROTECTED]> wrote:
> 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 < [EMAIL PROTECTED]> 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: [email protected]
> Search: http://radiantcms.org/mailing-list/search/
> Site:
> http://lists.radiantcms.org/mailman/listinfo/radiant
>
>
_______________________________________________
Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant
_______________________________________________ Radiant mailing list Post: [email protected] Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
