Create Custom controllers and Views in Radiant

24 views
Skip to first unread message

Shanison

unread,
Mar 9, 2011, 9:25:44 AM3/9/11
to Radiant CMS: Dev
Hi,

I have been searching to see if Radiant is able to integrate into
existing projects. And I saw this in the mail archive
http://www.mail-archive.com/rad...@radiantcms.org/msg04311.html It
seems that we can only package our existing projects as an extension
and put it in the Radiant project, but not the other way round.
However, I don’t understand that why we can’t do it.

In radiant project, there is no app folder, where it should contain
controllers, helpers and views. So why can’t we create the directory
in this project. E.g. app/customs_controller.rb, and create an action
inside, and create the views. Now we just modify the routes.rb in
config/routes.rb to be able to map to this controller. Then we are
able to do any dynamic pages that we wanted. Isn’t it?

One of the concerns is that if we do this the future upgrade of
Radiant maybe difficult?

Thank you very much.
Shanison

Jim Gay

unread,
Mar 12, 2011, 2:22:04 PM3/12/11
to radiant...@googlegroups.com, Shanison

Definitely don't alter the source of radiant to run your site; it will
only lead to pain down the road.

I wrote a bit about this topic
http://www.saturnflyer.com/blog/jim/2010/04/14/radiant-projects-and-rails-applications/
http://www.saturnflyer.com/blog/jim/2010/04/14/radiant-and-plugins/

The next release of Radiant will be 1.0 and will be the last Rails 2.3
version (barring any maintenance releases). A following Rails 3
version will change what you can and can't do.

--
Jim Gay
Saturn Flyer LLC
http://www.saturnflyer.com
571-403-0338

Shanison

unread,
Mar 14, 2011, 12:24:35 AM3/14/11
to Radiant CMS: Dev
What I am saying is not directly go and modify Radiant's source
code.What I am saying is in the radiant project I created e.g.
TestProject.In this TestProject, it doesn't have any app folder. For
default ruby on rails project, it should have this app folder which
contains controllers, models, views. So I am thinking why not we
create this app folder, put our custom controllers and views inside
this.

e.g we can create custom_controller.rb
class CustomController < ApplicationController
def show_me
#custom methods that retrieve dynamic contents from database
end
end

Then we add this route to this /custom/show_me.html to the routes.
Then we are able to show our custom dynamic pages? So we don't have to
do that in extensions.

I checked the Radiant source code, if I understand correctly, it
doesn't load the Rails_Root app folder, but Radiant_Root app folder.
So creating this app folder won't really loaded as well. But we can
add this folder directory to config.load_path to load the app folder.
The thing is I don't really understand why Radiant don't want to let
developers add custom app folder but need to use extensions only.

On Mar 13, 3:22 am, Jim Gay <j...@saturnflyer.com> wrote:
> On Wed, Mar 9, 2011 at 9:25 AM, Shanison <lxsh...@gmail.com> wrote:
> > Hi,
>
> > I have been searching to see if Radiant is able to integrate into
> > existing projects. And I saw this in the mail archive
> > http://www.mail-archive.com/radi...@radiantcms.org/msg04311.html It
> > seems that we can only package our existing projects as an extension
> > and put it in the Radiant project, but not the other way round.
> > However, I don’t understand that why we can’t do it.
>
> > In radiant project, there is no app folder, where it should contain
> > controllers, helpers and views.  So why can’t we create the directory
> > in this project. E.g. app/customs_controller.rb, and create an action
> > inside, and create the views. Now we just modify the routes.rb in
> > config/routes.rb to be able to map to this controller. Then we are
> > able to do any dynamic pages that we wanted. Isn’t it?
>
> > One of the concerns is that if we do this the future upgrade of
> > Radiant maybe difficult?
>
> > Thank you very much.
> > Shanison
>
> Definitely don't alter the source of radiant to run your site; it will
> only lead to pain down the road.
>
> I wrote a bit about this topichttp://www.saturnflyer.com/blog/jim/2010/04/14/radiant-projects-and-r...http://www.saturnflyer.com/blog/jim/2010/04/14/radiant-and-plugins/

Jim Gay

unread,
Mar 18, 2011, 3:10:08 PM3/18/11
to radiant...@googlegroups.com, Shanison
On Mon, Mar 14, 2011 at 12:24 AM, Shanison <lxs...@gmail.com> wrote:
> What I am saying is not directly go and modify Radiant's source
> code.What I am saying is in the radiant project I created e.g.
> TestProject.In this TestProject, it doesn't have any app folder. For
> default ruby on rails project, it should have this app folder which
> contains controllers, models, views. So I am thinking why not we
> create this app folder, put our custom controllers and views inside
> this.
>
> e.g we can create custom_controller.rb
> class CustomController < ApplicationController
>  def show_me
>    #custom methods that retrieve dynamic contents from database
>  end
> end
>
> Then we add this route to this /custom/show_me.html to the routes.
> Then we are able to show our custom dynamic pages? So we don't have to
> do that in extensions.
>
> I checked the Radiant source code, if I understand correctly, it
> doesn't load the Rails_Root app folder, but Radiant_Root app folder.
> So creating this app folder won't really loaded as well. But we can
> add this folder directory to config.load_path to load the app folder.
> The thing is I don't really understand why Radiant don't want to let
> developers add custom app folder but need to use extensions only.

That's a good question that probably has some historical backing but I
don't really see a reason to ignore the Rails.root app directory
either.
The way routes are loaded would probably need to change a bit. Using
extensions helps with separation of concerns and has probably
contributed to the development of extensions.

Have you already tried adding the directory to your load path? And did
you need to do anything different to get your routes working?

Unless anyone has a strong argument not to allow this, I'd happily
accept a patch (with specs!).

> --
> Radiant CMS Dev Mailing List
> Post:        radiant...@googlegroups.com
> Unsubscribe: radiantcms-de...@googlegroups.com
> Group Site:  http://groups.google.com/group/radiantcms-dev/

Shanison

unread,
Apr 4, 2011, 9:10:15 PM4/4/11
to radiant...@googlegroups.com
I did try adding custom controllers and models and views to the Radiant created projects. I even add the directory to the load_paths. However, the controller is still not loaded. I think right now, the only way of creating custom controllers is to wrap it as an extensions which would then be loaded by Radiant. 
Reply all
Reply to author
Forward
0 new messages