I started using Radiant and appreciate much its elegant interface. As
a user I find it easy to use the Radiant interface for creating
new pages and developing complex webpages with minimal effort.
I wonder if there is a way to create certain pages automatically
using some kind of script.
The situation is that we have weekly updates to our climate monitoring
webpage. For this, about 50 images have to be uploaded to the site
and the corresponding pages built every week. Wonder if Radiant could be
provided instructions to do this using a script than a person sitting
and typing it all in.
Thanks for any pointers,
saji
Saji N. Hameed
APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 [email protected]
KOREA
You could write a Ruby script that you invoke with script/runner, or
better yet, a Rake task. It will require some knowledge of the inner
workings of Radiant (at least how the models interact).
Alternatively, if you’re not comfortable with using the shell,
Capistrano could help you automate this, especially if the images are
local and not from external service.
Dear Sean,
Thank you for the tips. I am comfortable with writing shell or
Ruby scripts for this task, but have no idea of the inner workings of
Radiant. I have briefly looked at the Capistrano manuals and it
is a possible tool for my purpose.
If there is an example showing how to use scripting (ruby/bash) for
this kind of job, I would be grateful to learn from it.
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in eval' from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from script/runner:3
(/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45:
undefined method each' for #<PagePart:0xb765b49c> (NoMethodError) from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:137:inreplace’
from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/associations.rb:950:in parts=' from (eval):13 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ineval’
from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
from script/runner:3
Thanks very much. I ran the following code (included inside a file test.rb)
body = PagePart.new
would be greatly appreciated.
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `eval’
Thanks very much. I put child.parts as an array.
child.parts = [ body ]
Now the error is while
saving.
child.save!
Here is the error message. Do I need to enter pass on
login and password information through the script? If so how may i do
that. Or what else could be the source of the error?
Thanks much for your patience and kind help.
saji
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45:
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/validations.rb:764:in save_without_transactions!': Validation failed: Parts is invalid (ActiveRecord::RecordInvalid) from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/transactions.rb:133:insave!’
from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in transaction' from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/transactions.rb:95:intransaction’
from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/transactions.rb:121:in transaction' from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/transactions.rb:133:insave!’
from (eval):16
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in eval' from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from script/runner:3
I prefer the following, as it gives me the necessary associations of
things to one another. Perhaps the other code is failing as it is
missing the part name of “body”?
require ‘config/environment’
parent = Page.find_by_url(’/request’)
50.times do |i|
child = parent.children.build(
:title => “Page #{i}”,
:breadcrumb => “Page #{i}”,
:slug => “page-#{i}”)
child.parts.build(
:content => “This is page #{i}”,
:name => “body”)
child.save!
end