Re: RecordTags extension

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

[email protected]

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

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

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

[email protected]

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

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

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