On Sep 9, 2006, at 11:27, David wrote:
Is there away to access GET parameters in a behaviour?
site.com/something/1 translates in the behaviour to parameters[:id]
? it
dosent have to be like this, just an example?
I recently wrote a Radiant Behavior that uses the GET querystring:
Simply Get –
Takes a querystring ‘q’ and renders the child of this page with
matching slug.
I built it into a Rails plugin, available via http:
http://a3online.com/simply_get_behavior.tar.gz
Or, see the following Ruby code <<EXAMPLE
class SimplyGetBehavior < Behavior::Base
register “Simply Get”
description %{
Takes a querystring ‘q’ and renders the child of this page with
matching slug.
}
attr_accessor :page_headers
def process(request, response)
# can’t process query in find_page_by_url since request object
is not
# defined at that stage
query = request.parameters[:q]
if not query.to_s.strip.empty?
@found = false
@request, @response = request, response
@query = query.to_s.strip
if @matched = @page.children.find(:first, :conditions =>
[“slug = ‘%s’”, @query])
@found = true
@response.headers[‘Status’], @response.headers[‘Location’] =
‘302’, @matched.url
else
@page = @page.children.find(:first, :conditions =>
“behavior_id = ‘Page Missing’”) || nil
super
end
@request, @response = nil, nil
else
super
end
end
def cache_page?
false
end
def page_headers
if @found
super
else
{ ‘Status’ => ‘404 Not Found’ }
end
end
end
EXAMPLE
Hope this helps
*Mars
( <> … <> )