[Radiant] Chaching and getting id from url
Fabrizio Taddei
fabrizio_taddei at yahoo.it
Mon Apr 23 14:42:09 CDT 2007
Hi everybody,
I've developed an extension that display a list of
links, taken from a database table, in a page of my site called
links.
By clickking on the title of a link a "singlelink"
page will be opened.
In this page is displayed a description of
the link.
To select the single link I' ve created a
tag.
<!--
D(["mb","\u003cfont face\u003d\"Arial\" size\u003d\"2\"\>\u003cspan lang\u003d\"EN-GB\" style\u003d\"font-size:12pt\"\>\u003c/span\>\u003c/font\> \u003c/div\>\n\u003cdiv\>\u003cfont face\u003d\"Times New Roman\" size\u003d\"3\"\>\u003cspan lang\u003d\"EN-GB\" style\u003d\"font-size:12pt\"\>This tag pass the "link id" by the URL and another \ntag get the id from the URL and select the record from the db \ntable.\u003c/span\>\u003c/font\>\u003c/div\>\n\u003cdiv\>\u003cfont face\u003d\"Times New Roman\" size\u003d\"3\"\>\u003cspan lang\u003d\"EN-GB\" style\u003d\"font-size:12pt\"\>\u003cfont face\u003d\"Arial\" size\u003d\"2\"\>\u003c/font\>\u003cfont face\u003d\"Arial\" size\u003d\"2\"\>\u003c/font\>\u003cbr\>This is the code of my tags:\u003cbr\>\u003cbr\>tag \n"links:each:link_to_single" do |tag|\u003cbr\> curURL \u003d \nrequest.request_uri\u003cbr\> %{<a \nhref\u003d"#{curURL}/singlelink?id\u003d\u003cWBR\>#{\u003ca
href\u003d\"http://tag.locals.lnk.id\" target\u003d\"_blank\" onclick\u003d\"return top.js.OpenExtLink(window,event,this)\"\>tag.locals.lnk.id\u003c/a\>}">#{tag.locals.lnk.site_name}</a>}\u003cbr\> \nend\u003cbr\>\u003cbr\> tag "links:single" do |tag|\u003cbr\> content \u003d \n''\u003cbr\> curId \u003d \nrequest.params['id']\u003cbr\> lnk \u003d Link.find_by_id \ncurId\u003cbr\> tag.locals.lnk \u003d lnk\u003cbr\> \n content << tag.expand\u003cbr\> content\u003cbr\> \nend\u003cbr\>\u003cbr\>With this tags I form url like: /en/singlelink?id\u003d2\u003cbr\>\u003cbr\>It works \nvery well, but now I've got problems with the cache. I've read some documents \nabout Rails Caching and I've learned that I must form url like this: \n/en/singlelink/2.\u003cbr\>\u003cbr\>I've tryed to add in the file "extension.rb" a \nmap.connect like this:\u003cbr\>\u003cbr\> map.comnect
\n'en/singlelink/:id'\u003cbr\> :controller \u003d> \n'links'\u003cbr\> :requirements \u003d> { :id \u003d> \n/\\d+/},\u003cbr\> :page \u003d> nil\u003cbr\>\u003cbr\>and \nchange the tag in this way:\u003cbr\>\u003cbr\>tag "links:each:link_to_single" do \n|tag|\u003cbr\> curURL \u003d request.request_uri\u003cbr\> %{<a \nhref\u003d"#{curURL}/singlelink/#{\u003ca href\u003d\"http://tag.locals.lnk.id\" target\u003d\"_blank\" onclick\u003d\"return top.js.OpenExtLink(window,event,this)\"\>tag.locals.lnk.id\u003c/a\>}">#{tag.locals.lnk.site_name}</a>}\u003cbr\> \nend\u003cbr\>\u003cbr\>But it doesn't work.\u003cbr\>\u003cbr\>Is there someone who can explain me how \ncan I solve my caching problems?",1]
);
//-->
This tag pass the "link id" by the URL and another
tag get the id from the URL and select the record from the db
table.
This is the code of my tags:
tag
"links:each:link_to_single" do |tag|
curURL =
request.request_uri
%{<a
href="#{curURL}/singlelink?id=#{tag.locals.lnk.id}">#{tag.locals.lnk.site_name}</a>}
end
tag "links:single" do |tag|
content =
''
curId =
request.params['id']
lnk = Link.find_by_id
curId
tag.locals.lnk = lnk
content << tag.expand
content
end
With this tags I form url like: /en/singlelink?id=2
It works
very well, but now I've got problems with the cache. I've read some documents
about Rails Caching and I've learned that I must form url like this:
/en/singlelink/2.
I've tryed to add in the file "extension.rb" a
map.connect like this:
map.comnect
'en/singlelink/:id'
:controller =>
'links'
:requirements => { :id =>
/\d+/},
:page => nil
and
change the tag in this way:
tag "links:each:link_to_single" do
|tag|
curURL = request.request_uri
%{<a
href="#{curURL}/singlelink/#{tag.locals.lnk.id}">#{tag.locals.lnk.site_name}</a>}
end
But it doesn't work.
Is there someone who can explain me how
can I solve my caching problems?<!--
D(["mb","\u003cbr\>\u003cbr\>\u003c/span\>Thank's everybody.\u003c/font\>\u003cfont face\u003d\"Arial\" size\u003d\"2\"\>\u003cspan style\u003d\"font-size:10pt;font-family:Arial\"\>\u003c/span\>\u003c/font\>\u003c/div\>\u003c/div\>\n",0]
);
D(["ce"]);
//-->
Thank's everybody.
___________________________________
L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail: http://it.docs.yahoo.com/nowyoucan.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.radiantcms.org/pipermail/radiant/attachments/20070423/93208f0f/attachment.html
More information about the Radiant
mailing list