# Error Trying to Use script/console to Create Pages

**URL:** <https://www.ruby-forum.com/t/error-trying-to-use-script-console-to-create-pages/75981>\
**Category:** Radiant CMS\
**Created:** [November 14, 2006, 9:03pm UTC](https://www.ruby-forum.com/t/error-trying-to-use-script-console-to-create-pages/75981 "2006-11-14T21:03:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radiant\_List](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@Radiant\_List](https://www.ruby-forum.com/u/Radiant_List)\
**Post date:** [November 14, 2006, 9:03pm UTC](https://www.ruby-forum.com/t/error-trying-to-use-script-console-to-create-pages/75981/1 "2006-11-14T21:03:56Z")

</div>

Hello Radiant Folk!

I’m a Radiant neophyte with a little bit of Rails experience. Thank you  
so  
much for making Radiant such an elegant, usable and slick CMS, I’m very  
excited about using it for some upcoming projects.

I’ve long had a dream of being able to create simple,  
hierarchical-navigation based sites using simple scripting or, even  
better,  
YAML/XML etc. to generate the framework and initial content. I’m  
hopeful I  
can figure out a way to do this using Radiant. I’ve been experimenting  
with  
some approaches using the rails console.

I first tried creating a pages\_controller instance then running the new  
method after setting the params property. This didn’t work due to the  
use  
of the request object in that method. I then  
tried adapting that method so it could work as a simple page creation  
function. I am running into a " undefined method `stringify\_keys!’ for  
“body”:String" message however.

Here’s my code:

def new\_page(  
title,parts,slug,breadcrumb,parent=1,behavior="",layout\_id=  
“1”) page = Page.  
new  
page.slug = slug  
page.breadcrumb = breadcrumb  
page.parent = Page.find\_by\_id(parent)  
parts.each  
do |part|  
new\_part = PagePart.new(part[  
:name])  
new\_part.filter\_id = part[  
:filter\_id]  
new\_part.content = part[:content]  
page.parts \<\< new\_part

end  
page.save  
end

then I run

new\_page(“test automatic”, [{:name=\>“body”, :filter\_id=\>“Markdown”,  
:content=\>""}, {:name=\>“extended”,:filter\_id=\>"",  
:content=\>""}],“test-automatic”,“test automatic”)

and get the error

NoMethodError: undefined method `stringify_keys!' for "body":String from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1506:in`attributes=’  
from  
./script/…/config/…/config/…/vendor/rails/activerecord/lib/active\_record/base.rb:1354:in  
`initialize_without_callbacks' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:236:in`initialize’  
from (irb):63:in `new_page' from (irb):62:in`new\_page’  
from (irb):70  
from :0

I’ve also tried creating the part\_parts object using a straightforward  
call  
from the console (p= PagePart.new(“body”)) with the same error  
resulting.

I’m on a OS X 10.4 mac with a slightly outdated install of Darwinports,  
but  
everything seems to be running local here, not off my Rails install.

Any thoughts on how I can batch-generate pages or fix this script?

Thanks,

Ethan
