July 15th, 2008, 08:44 AM
Render_to_string causing an error
Hi im having some trouble with a system i am creating. I am attempting to make a CMS in rails. I am having a trouble with a certain aspect of this. Bear with me whilst i try to explain myself.
The first thing i have is a table of page contents this page content can contain any text, you can also place snippets. (Ive taken that term from radiant). So if you want a ceratin bit of code to appear you enter
so for example i have created a news plugin fro my system which would be called using
<snippet:controller:action variable1 variable2>
This code should render a list of latest news.
So i have the following file structure.
What i am trying to do is on the content page it does a regular expression match for the snippet string and extracts the controller, action, and variables which i have managed to do successfully. It will then run the controller/action. This controller/action will then create the component and send that back as a string.
At the moment the calls to the necesary external functions are hardcoded but this will change.
@page_content = @content.content;
while @page_content =~ /\<snippet:(.*):([^ ]*) *(.*)\>/
@variables = $3.to_i;
@object = NewsController.new()
@news_snippets = @object.send 'small_news', @variables
@page_content = @page_content.gsub(/\<snippet:(.*):([^ ]*) *(.*)\>/, 'test')
When this is run i get an error in the small_news definition.
render_to_string :partial => 'news/small_news'
This is the Trace:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.body=
What would be causing the error if i place the render_to_string within the default_controller/content_page definition it will render fine.
I have created a normal controller and view for a page within the news controller which render sthe same template to a variable and this works fine. It is only when i call the render_to_string from another controller?
This may not be the way to go with this but i wanted to create 'plugins' for my cms system which need to be external to everything else on the system so this was in my mind the best way to do it?