Accessing Flash/Session in Radiant Tags?

View: New views
4 Messages — Rating Filter:   Alert me  

Accessing Flash/Session in Radiant Tags?

by jaaronfarr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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
_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Re: Accessing Flash/Session in Radiant Tags?

by Casper Fabricius :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>   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

On 11/02/2008, at 6:53, J Aaron Farr wrote:

>
> 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
> _______________________________________________
> Radiant mailing list
> Post:   Radiant@...
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Re: Accessing Flash/Session in Radiant Tags?

by jaaronfarr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Casper Fabricius <me@...> writes:

>>   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

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
_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Re: Accessing Flash/Session in Radiant Tags?

by Sean Cribbs-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> 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
_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant