Forum: Radiant CMS automated page building

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Saji Njarackalazhikam H. (Guest)
on 2007-05-16 07:36
(Received via mailing list)
Dear All,

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 
removed_email_address@domain.invalid
KOREA
Sean C. (Guest)
on 2007-05-16 07:56
(Received via mailing list)
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.

Sean
Saji Njarackalazhikam H. (Guest)
on 2007-05-16 08:22
(Received via mailing list)
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.

Thanks,
saji

* Sean C. <removed_email_address@domain.invalid> [2007-05-15 20:55:25 -0700]:

> > Dear All,
> > provided instructions to do this using a script than a person sitting
> > KOREA
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant
--
Saji N. Hameed

APEC Climate Center                  +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 
removed_email_address@domain.invalid
KOREA
Daniel S. (Guest)
on 2007-05-16 08:28
(Received via mailing list)
require 'config/environment'

parent = Page.find_by_url('/path/to/parent')

50.times do {|i|
  child = Page.new
  child.parent = parent
  child.title = "Page #{i}"
  child.breadcrumb = "Page #{i}"
  child.slug = "page-#{i}"
  body = PagePart.new
  body.content = "This is page #{i}"
  child.parts = body
  child.save!
}
Saji Njarackalazhikam H. (Guest)
on 2007-05-16 09:06
(Received via mailing list)
Hi Daniel,
Thanks very much. I ran the following code (included inside a file
test.rb)

# Start of code
parent = Page.find_by_url(/articles/)

i=1
  child = Page.new
  child.parent = parent
  child.title = "Page #{i}"
  child.breadcrumb = "Page #{i}"
  child.slug = "page-#{i}"
  body = PagePart.new
  body.content = "This is page #{i}"
  child.parts = body
  child.save!
# End of code

And then went to root of my application and ran:

"script/runner -e production test.rb"

Unfortunately I got the following error messages. Any further tips
would be greatly appreciated.

saji

/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45:
undefined method `strip' for /articles/:Regexp (NoMethodError)

        from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/app/models/page.rb:129:in
`find_by_url'

        from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/app/models/page.rb:151:in
`find_by_url'

        from (eval):3
        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:in
`gem_original_require'
        from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
        from script/runner:3


* Daniel S. <removed_email_address@domain.invalid> [2007-05-16 14:24:19
+1000]:

>   body = PagePart.new
> > To: removed_email_address@domain.invalid
> > Thanks,
> > images are
> > > > new pages and developing  complex webpages with minimal effort.
> > > > and typing it all in.
> > removed_email_address@domain.invalid
> > > Search: http://radiantcms.org/mailing-list/search/
> > _______________________________________________
> > Radiant mailing list
> > Post:   removed_email_address@domain.invalid
> > Search: http://radiantcms.org/mailing-list/search/
> > Site:   http://lists.radiantcms.org/mailman/listinfo/radiant
> >
> _______________________________________________
> Radiant mailing list
> Post:   removed_email_address@domain.invalid
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

--
Saji N. Hameed

APEC Climate Center                  +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 
removed_email_address@domain.invalid
KOREA
Sean C. (Guest)
on 2007-05-16 09:27
(Received via mailing list)
Very funny Daniel ;).

Sean
Sean C. (Guest)
on 2007-05-16 09:28
(Received via mailing list)
Saji,

Make sure to put quotes around that URL.  It should be a string, not a
regex.

parent = Page.find_by_url("/articles/")

Sean
Daniel S. (Guest)
on 2007-05-16 09:34
(Received via mailing list)
> Subject: Re: [Radiant] automated page building
>
> Very funny Daniel ;).
>
> Sean

Funny? That code is pretty much verbatim from a script I have to
generate a bunch of pages for benchmarking find_by_url.

Dan.
Sean C. (Guest)
on 2007-05-16 10:14
(Received via mailing list)
Well, I thought it was funny.  Don't mind the crazy person! (me)

Sean
Saji Njarackalazhikam H. (Guest)
on 2007-05-16 11:02
(Received via mailing list)
Sean,

Thanks..

With the URL now enclosed by quotes, I get the following error ...hmmm.
what could i be doing wrong?

saji

# Start of Ruby code
#require 'config/environment' ! i commented this out

parent = Page.find_by_url("/articles/")

i=1
child = Page.new
child.parent = parent
child.title = "Page #{i}"
child.breadcrumb = "Page #{i}"
child.slug = "page-#{i}"
body = PagePart.new
body.content = "This is page #{i}"
child.parts = body
child.save!

# End of Ruby code

START OF ERROR MESSAGE
-------------------------------

(/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:in
`replace'
        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: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:in
`gem_original_require'
        from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
        from script/runner:3


END OF ERROR MESSAGE
-----------------------------------------------
* Sean C. <removed_email_address@domain.invalid> [2007-05-15 22:27:52 -0700]:

> > 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'
> > > parent = Page.find_by_url('/path/to/parent')
> > >       child.save!
> > > > Dear Sean,
> > > > * Sean C. <removed_email_address@domain.invalid> [2007-05-15 20:55:25 -0700]:
> > > > > Sean
> > > > > >
> > > > > > saji
> > > > > > Radiant mailing list
> > > > --
> > > > Search: http://radiantcms.org/mailing-list/search/
> >
> _______________________________________________
> Radiant mailing list
> Post:   removed_email_address@domain.invalid
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

--
Saji N. Hameed

APEC Climate Center                  +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 
removed_email_address@domain.invalid
KOREA
Daniel S. (Guest)
on 2007-05-16 12:14
(Received via mailing list)
child.parts should be an array
Saji Njarackalazhikam H. (Guest)
on 2007-05-16 12:54
(Received via mailing list)
Dear Dan,

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:in
`save!'
        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:in
`transaction'
        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:in
`save!'
        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:in
`gem_original_require'
        from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
        from script/runner:3


* Daniel S. <removed_email_address@domain.invalid> [2007-05-16 18:09:53
+1000]:

> > Sean,
> > #require 'config/environment' ! i commented this out
> > body.content = "This is page #{i}"
> > child.parts = body
> > child.save!
> _______________________________________________
> Radiant mailing list
> Post:   removed_email_address@domain.invalid
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

--
Saji N. Hameed

APEC Climate Center                  +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 
removed_email_address@domain.invalid
KOREA
Francesco L. (Guest)
on 2007-05-16 13:19
(Received via mailing list)
Saji Njarackalazhikam H. ha scritto:
> ...
I think it should be child.parts << body

ciao


--
Francesco L.
Ymir s.r.l.
Viale Verona 190/11
38100 Trento
Adam W. (Guest)
on 2007-05-16 14:48
(Received via mailing list)
On May 16, 2007, at 5:16 AM, Francesco L. wrote:

>>
>> ...
> I think it should be child.parts << body

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
Sean C. (Guest)
on 2007-05-16 19:35
(Received via mailing list)
+1 for model.association_name.build

Sean
Saji Njarackalazhikam H. (Guest)
on 2007-05-17 05:00
(Received via mailing list)
Thank you, this works... thanks to all who helped.
best wishes,
saji
* Adam W. <removed_email_address@domain.invalid> [2007-05-16 06:49:54 -0400]:

> >>
> require 'config/environment'
>      :name    => "body")
>    child.save!
> end
> _______________________________________________
> Radiant mailing list
> Post:   removed_email_address@domain.invalid
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

--
Saji N. Hameed

APEC Climate Center                  +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 
removed_email_address@domain.invalid
KOREA
This topic is locked and can not be replied to.