Hi all,
I’m doing some work on an extension, and I’m run into an issue. I’d
like to pass validation errors on a form back to the tag that draws the
form. ala:
module FormTags
include Radiant::Taggable
desc %{
Displays the form
}
tag “form” do |tag|
form = ‘’
if flash[:error]
form << ‘’+flash[:error]+‘’
end
…
end
end
So, how do I access that? controller.flash doesn’t work, and nor does
flash (or passing a variable through the class scope).
Thanks for any ideas-
–
Matthew B. :: 607 227 0871
Resume & Portfolio @ http://madhatted.com
Tags exist in the Page model (or a subclass) when processing, so they
really only have access to the model layer. However, the Page model
has available to it the request and response objects. There are other
ways to tackle the problem, but you could try getting the information
from the response object. I believe the flash is stored in the session.
if response.session[‘flash’][:error]
do something
end
Cheers,
Sean
On Mon, 2007-04-23 at 22:44 -0400, John W. Long wrote:
No the flash won’t work because sessions are off for the SiteController.
Oh hell that’s right. So I could either go in and enable them (alter
radiant), or maybe I’ll just hack it instead.
But yeah, knowing that response
is in the scope should give me a start
if I do use sessions. Thanks alot Sean, John.
–
Matthew B. :: 607 227 0871
Resume & Portfolio @ http://madhatted.com
Sean C. wrote:
Tags exist in the Page model (or a subclass) when processing, so they
really only have access to the model layer. However, the Page model
has available to it the request and response objects. There are other
ways to tackle the problem, but you could try getting the information
from the response object. I believe the flash is stored in the session.
if response.session[‘flash’][:error]
do something
end
No the flash won’t work because sessions are off for the SiteController.
So there is really not an easy answer.
–
John L.
http://wiseheartdesign.com
Then in the tag:
request.params[:error]
Only issue is rails doesn’t put the GET params into the request.params
object, it only puts them in the params object, which isn’t accessible
from the tag.
Try request.parameters[:error]. params is a shorthand introduced in
ActionController I believe.
Sean
On Tue, 2007-04-24 at 09:50 -0500, Sean C. wrote:
ActionController I believe.
That did it! Thanks Sean.
–
Matthew B. :: 607 227 0871
Resume & Portfolio @ http://madhatted.com
On Mon, 2007-04-23 at 21:00 -0500, Sean C. wrote:
Tags exist in the Page model (or a subclass) when processing, so they
really only have access to the model layer. However, the Page model
has available to it the request and response objects. There are other
ways to tackle the problem, but you could try getting the information
from the response object. I believe the flash is stored in the session.
if response.session[‘flash’][:error]
do something
end
Ugh, well as was mentioned sessions are off, So I’m instead attempting
to pass the info back in a get string during a redirect:
redirect_to “action”=>“show_page”, “url”=>[“about”],
“controller”=>“site”, “error” => error
Then in the tag:
request.params[:error]
Only issue is rails doesn’t put the GET params into the request.params
object, it only puts them in the params object, which isn’t accessible
from the tag.
Any ideas on that?
–
Matthew B. :: 607 227 0871
Resume & Portfolio @ http://madhatted.com
What if you set a local variable in the Page model? You could use an
attr_accessor method called Page#flash.
Or, you could use a cattr_accessor and define some flash methods like
this:
class Page < …
cattr_accessor :flash
def self.flash=(message)
@@flash = {}
@@flash[:message] = message
end
def self.flash(key)
@@flash.delete(key)
end
end
Obviously, that logic isn’t the greatest, and I haven’t tested this.
If it works though please let us know.
On Apr 24, 2007, at 8:30 AM, Matthew B. wrote:
from the response object. I believe the flash is stored in the
Oh hell that’s right. So I could either go in and enable them (alter
Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Ryan H.
Art of Mission, Inc.
3720 Gattis School Rd #800 PMB 245
Round Rock, TX 78664
800-722-1492 (phone)
www.artofmission.com
[email protected]