# Page\_type as a parameter

**URL:** <https://www.ruby-forum.com/t/page-type-as-a-parameter/192501>\
**Category:** Radiant CMS\
**Created:** [July 31, 2010, 7:49pm UTC](https://www.ruby-forum.com/t/page-type-as-a-parameter/192501 "2010-07-31T19:49:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario\_TSL](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df705f/32.png) [@Mario\_TSL](https://www.ruby-forum.com/u/Mario_TSL)\
**Post date:** [July 31, 2010, 7:49pm UTC](https://www.ruby-forum.com/t/page-type-as-a-parameter/192501/1 "2010-07-31T19:49:53Z")

</div>

I am trying to pass a page\_type parameter (via query string) to the page  
controller new and create actions.

[http://localhost:3000/admin/pages/5/children/new?page\_type=event](http://localhost:3000/admin/pages/5/children/new?page_type=event)

The goal is for the new page to appear showing it’s page type-specific  
fields already. Normally, when creating a new page you click the add  
button on the page index, you arrive at the new page screen, you select  
the page type and AFTER you click “Create Page” you finally end up with  
the page in its typed glory.

The thing I’m trying to avoid is having the user save the page in two  
steps. 1) Create a basic page setting the type before saving, 2) When  
the page reloads fill out the type-specific fields and save again.

It’s easy enough to add a feature to the page index that allows for page  
type selection and invokes the page#new action with a page type. I have  
attempted to mixin some modules into Admin::ResourceController and  
Admin::PagesController with limited success.

I was looking for the least obtrusive way to do this, but after lots of  
failed attempts, I’m less concerned with how obtrusive/clean the change  
is.

I would have thought this fairly simple but after 3 hours it’s seeming  
less simple. Any ideas?

Admin::PagesController.class\_eval do  
alias old\_new new  
alias old\_create create

def new  
puts ‘i made it to new’ #=\> seeing this  
klass = params[:page\_type].camelize.constantize rescue model\_class  
self.model = klass.new\_with\_defaults(config)  
if params[:page\_id].blank?  
self.model.slug = ‘/’  
end  
response\_for :singular  
end

def create  
puts ‘i made it to create’ #=\> not seeing this  
model.update\_attributes!(params[model\_symbol])  
announce\_saved  
response\_for :create  
end  
end

I’m using Radiant 0.8.1.

Thanks,  
Mario T. Lanza
