[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 &quot;link id&quot; 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&quot;links:each:link_to_single&quot; do |tag|\u003cbr\>   curURL \u003d \nrequest.request_uri\u003cbr\>   %{&lt;a \nhref\u003d&quot;#{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\>}&quot;&gt;#{tag.locals.lnk.site_name}&lt;/a&gt;}\u003cbr\>  \nend\u003cbr\>\u003cbr\> tag &quot;links:single&quot; do |tag|\u003cbr\>    content \u003d \n&#39;&#39;\u003cbr\>     curId \u003d \nrequest.params[&#39;id&#39;]\u003cbr\>     lnk \u003d Link.find_by_id \ncurId\u003cbr\>     tag.locals.lnk \u003d lnk\u003cbr\>    \n content &lt;&lt; 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&#39;ve got problems with the cache. I&#39;ve read some documents \nabout Rails Caching and I&#39;ve learned that I must form url like this: \n/en/singlelink/2.\u003cbr\>\u003cbr\>I&#39;ve tryed to add in the file &quot;extension.rb&quot; a \nmap.connect like this:\u003cbr\>\u003cbr\>    map.comnect
 \n&#39;en/singlelink/:id&#39;\u003cbr\>        :controller \u003d&gt; \n&#39;links&#39;\u003cbr\>        :requirements \u003d&gt; { :id \u003d&gt; \n/\\d+/},\u003cbr\>        :page \u003d&gt; nil\u003cbr\>\u003cbr\>and \nchange the tag in this way:\u003cbr\>\u003cbr\>tag &quot;links:each:link_to_single&quot; do \n|tag|\u003cbr\>   curURL \u003d request.request_uri\u003cbr\>   %{&lt;a \nhref\u003d&quot;#{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\>}&quot;&gt;#{tag.locals.lnk.site_name}&lt;/a&gt;}\u003cbr\>  \nend\u003cbr\>\u003cbr\>But it doesn&#39;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&#39;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