Forum: Radiant CMS page_type as a parameter

Posted by Mario T. Lanza (mlanza)
on 2010-07-31 19:49
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?p...

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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.