# Re: RecordTags extension

**URL:** <https://www.ruby-forum.com/t/re-recordtags-extension/104621>\
**Category:** Radiant CMS\
**Created:** [May 20, 2007, 9:37pm UTC](https://www.ruby-forum.com/t/re-recordtags-extension/104621 "2007-05-20T21:37:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 20, 2007, 9:37pm UTC](https://www.ruby-forum.com/t/re-recordtags-extension/104621/1 "2007-05-20T21:37:16Z")

</div>

Thank you, Mario, for making your extension available.  
It’s very well documented and record tags are easy to use.  
I have extended the ‘records’ tag adding a ‘SQL’ attribute where one can  
place a SQL statement that is executed via [model].find\_by\_sql.  
Here is the patched code:

```
    tag 'records' do |tag|
            raise TagError, "'#{tag.name}' tag must contain a 

```

‘model’  
attribute." unless tag.attr[‘model’]  
if tag.attr[‘SQL’]  
records =  
eval(“#{tag.attr[‘model’]}.find\_by\_sql(tag.attr[‘SQL’])”)  
else  
if tag.attr[‘id’]  
records =  
eval(“#{tag.attr[‘model’]}.find(tag.attr[‘id’])”)  
else  
records =  
eval(“#{tag.attr[‘model’]}.find(:all, :conditions =\>  
tag.attr[‘conditions’], :order =\> tag.attr[‘order’], :offset =\>  
tag.attr[‘offset’], :limit =\> tag.attr[‘limit’])”)  
end  
end  
tag.locals.records = records  
tag.expand  
end

I gave a look to the ‘record’ tag, used for showing individual records.  
The tags has an ‘id’ attribute that can be set manually in a dedicated  
radiant page. I was wondering how to make a radiant page showing  
individual records dynamic, i.e. selecting the record with the id passed  
as a request param. In this case the page acts as a template used for  
every record, avoiding the creation of distinct pages with the id value  
“hard coded” in each of them.  
I posed this same problem in a previous post, and tried new attempts at  
solving it, but have not been able to figure out a solution so far.

Luca

removed\_email\_address@domain.invalid

> Some of you had indicated an interest in my not-yet-mature extension for  
> rendering models. Basically, it allows you to use Radius tags to  
> display records from your Radiant database. Obviously, this is most  
> useful if you’ve created custom models and the back-end interface (an  
> extension) to maintain those models.

> You can download the extension at:  
> [http://www.boardgamerspastime.com/downloads/radiant/extensions/record\_tags.zip](http://www.boardgamerspastime.com/downloads/radiant/extensions/record_tags.zip)

> Please notify me of any issues you encounter. I’ve tested on Ubuntu.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 21, 2007, 7:05am UTC](https://www.ruby-forum.com/t/re-recordtags-extension/104621/2 "2007-05-21T07:05:55Z")

</div>

Gotcha! In Rails, you avail of request.parameters, not request.params as  
I tried to do (my lazyness in reading API docs being deservedly  
punished).  
So here is my patch of Mario’s code in order to get record information  
dynamically by id in a radiant page used as a template (I added an  
‘URI\_id’ attribute in the tag):  
tag ‘record’ do |tag|  
raise TagError, “‘#{tag.name}’ tag must contain a ‘model’  
attribute.” unless tag.attr[‘model’]  
raise TagError, “‘#{tag.name}’ tag must contain a ‘conditions’ or an  
‘id’ or an ‘URI\_id’ attribute.” unless tag.attr[‘conditions’] or  
tag.attr[‘id’] or tag.attr[‘URI\_id’]  
record = eval(“#{tag.attr[‘model’]}.find(:first, :conditions =\>  
tag.attr[‘conditions’], :order =\> tag.attr[‘order’])”) if  
tag.attr[‘conditions’]  
record = eval(“#{tag.attr[‘model’]}.find(#{tag.attr[‘id’]})”) if  
tag.attr[‘id’]  
#record =  
eval(“#{tag.attr[‘model’]}.find(request.request\_uri.split(‘/’).last)”)  
if tag.attr[‘URI\_id’]  
record = eval(“#{tag.attr[‘model’]}.find(request.parameters[‘id’])”)  
if tag.attr[‘URI\_id’]  
tag.locals.record = record  
tag.expand if record  
end

In [myext]\_extension.rb I added a route in order to pass the id as a  
request parameter which is stripped from the radiant page url:  
map.show\_singlelink ‘[radiant page url]/:id’, :controller  
=\> ‘site’, :action =\> ‘show\_page’,:url =\> ‘[radiant page url]’

Luca

lerzegov wrote:

> Thank you, Mario, for making your extension available.  
> I gave a look to the ‘record’ tag, used for showing individual records.  
> The tags has an ‘id’ attribute that can be set manually in a dedicated  
> radiant page. I was wondering how to make a radiant page showing  
> individual records dynamic, i.e. selecting the record with the id passed  
> as a request param. In this case the page acts as a template used for  
> every record, avoiding the creation of distinct pages with the id value  
> “hard coded” in each of them.  
> I posed this same problem in a previous post, and tried new attempts at  
> solving it, but have not been able to figure out a solution so far.
> 
> Luca
> 
> removed\_email\_address@domain.invalid
> 
> > Some of you had indicated an interest in my not-yet-mature extension for  
> > rendering models. Basically, it allows you to use Radius tags to  
> > display records from your Radiant database. Obviously, this is most  
> > useful if you’ve created custom models and the back-end interface (an  
> > extension) to maintain those models.
> 
> > You can download the extension at:  
> > [http://www.boardgamerspastime.com/downloads/radiant/extensions/record\_tags.zip](http://www.boardgamerspastime.com/downloads/radiant/extensions/record_tags.zip)
> 
> > Please notify me of any issues you encounter. I’ve tested on Ubuntu.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 30, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/re-recordtags-extension/104621/3 "2007-05-30T19:41:34Z")

</div>

Thanks, Luca.  
I will investigate this for integration for the next release (when time  
permits).  
Mario
