Forum: Radiant CMS Accessing Flash/Session in Radiant Tags?

Df24355fabf42d90c79d6c54e2d18634?d=identicon&s=25 J Aaron Farr (Guest)
on 2008-02-11 06:53
(Received via mailing list)
The scenerio is this:

The Comments extension has a controller that handles the comment form
and then redirects the request back to the originating Page (with the
comment now saved).  The form requires an email address, but at the
moment, when no email address is supplied, one just gets the classic
ugly Rails error page (with stack).

The trouble is that because of the redirect, the CommentController
cannot use the typical Rails validation code to display validation
error messages.  My thought was to try and fix this by stuffing the
error message into the controller `flash` or the session.  But there
doesn't appear to be any way to access flash from inside a tag.  It's
not part of the tag.globals or tag.locals.  Fixing this would require
patching the SiteController.

So my questions are:

   1) Is there any other way to access the flash or session data from
      a tag?

   2) Is there a better way to send back form validation messages to a
      Page? (*)

If not, I'll send a patch to the SiteController to bind the flash to a
the tag object.

(*) -- The Mailer extension gets around this problem by subclassing
the Page object, but that seems like a less than ideal approach since
at the moment, any type of Page can have comments, whereas subclassing
removes that option.

Thanks!

--
  J Aaron Farr     jadetower.com        [US] +1 724-964-4515
    馮傑仁         cubiclemuses.com     [HK] +852 8123-7905
2fd982df89c3c697c487514796393bc5?d=identicon&s=25 Casper Fabricius (Guest)
on 2008-02-11 11:06
(Received via mailing list)
>   1) Is there any other way to access the flash or session data from
>      a tag?


It can be done, but it requires a bit of patching. You need to put the
request and response objects in the globals for the tag to access, and
bear in mind that you need to reenable to sessions for sitecontroller:

module SiteControllerExt
   def self.included(base)
     base.class_eval {
       # This reenables the session for the SiteController -
session :on does not work!
       session :disabled => false
     }
   end
end
Df24355fabf42d90c79d6c54e2d18634?d=identicon&s=25 J Aaron Farr (Guest)
on 2008-02-11 11:11
(Received via mailing list)
Casper Fabricius <me@casperfabricius.com> writes:

>      base.class_eval {
>        # This reenables the session for the SiteController -
> session :on does not work!
>        session :disabled => false
>      }
>    end
> end

Thanks.

I thought about this, but it smelled bad to me, so I wanted to ask
around first.

--
  J Aaron Farr     jadetower.com        [US] +1 724-964-4515
    馮傑仁         cubiclemuses.com     [HK] +852 8123-7905
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (seancribbs)
on 2008-02-11 14:45
(Received via mailing list)
> So my questions are:
>
>    1) Is there any other way to access the flash or session data from
>       a tag?
>
>    2) Is there a better way to send back form validation messages to a
>       Page? (*)
>
>
There are two options I can think of here for question #2, and I don't
think you need to worry about #1.

First, when validation fails, you could simply render the page as your
output, using the special Radius tags you use to markup your form to
output the validation errors.

Second, you could use AJAX to post the comment.  Then if it fails, you
can send back various JS commands that display the validation errors.

A third but potentially less desirable option is not to subclass Page
like the Mailer extension does, but to modify the Page model directly.
Alias-chain the process method and then check for your comment post,
passing on to the original method if it wasn't a comment.

For Redken, we did add sessions to SiteController; however, I would only
do it if you are allowing visitor logins.  It doesn't seem worth it to
enable sessions just for flash messages.

Sean
This topic is locked and can not be replied to.