Hi All, I am looking for a way to dynamically load a view, inside a template, based on uri that does not officially exist inside of rails. i.e. a typical CMS system such as wordpress that stores the html from the pages in a database. I have found a page on the the rails wiki ( http://wiki.rubyonrails.org/rails/pages/HowToRunAnActionBeforeRoutes) that seems to be what I want, but lacking a few details (to me, anyway) . Is there a way to intercept an "unknown method" event? Has any one tried this or have thoughts on how to do it? Thanks! -- Matt Secoske http://www.secosoft.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060204/e672aa5f/attachment.html
On Feb 3, 2006, at 10:16 PM, Matt Secoske wrote:> I am looking for a way to dynamically load a view, inside a > template, based on uri that does not officially exist inside of rails.This makes me think you want something like this: <div> <%= get_html_at_uri ''http://host/document'' -%> </div> but this:> i.e. a typical CMS system such as wordpress that stores the html > from the pages in a database. I have found a page on the the rails > wiki http://wiki.rubyonrails.org/rails/pages/ > HowToRunAnActionBeforeRoutes) that seems to be what I want, but > lacking a few details (to me, anyway) ....makes me think you''re looking for something like this: class DynamicController < ApplicationController def show @code = DynamicContent.find(:id) end end In the view: <div> <%= @code -%> </div> -- -- Tom Mornini -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060204/ffd7cb7d/attachment.html
On 2/4/06, Tom Mornini <tmornini@infomania.com> wrote:> > On Feb 3, 2006, at 10:16 PM, Matt Secoske wrote: > >i.e. a typical CMS system such as wordpress that stores the html from the pages in a database. I have found a page on the the rails wiki http://wiki.rubyonrails.org/rails/pages/HowToRunAnActionBeforeRoutes) that seems to be what I want, but lacking a few details (to me, anyway) .> ...makes me think you''re looking for something like this: > > class DynamicController < ApplicationController > def show > @code = DynamicContent.find(:id) > end > end > > In the view: > > <div> > <%= @code -%> > </div> >Yes, I am definetly looking for the DynamicController version... In fact, my code is very similar to what you have here. My question is how do you tie this into rails such that it will be checked at some point in the rails dispatched request in a seamless manner. i.e. if a view does not exist for http://domain/controller/action then it calls my controller with the uri and allows me a chance to still display something. I have been tinkering with routes.rb, and am able to get that to /sometimes/ work. Any tips or explanations on how I can do this would be greatly appreciated. Thanks!! -- Matt Secoske http://www.secosoft.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060204/05655abc/attachment.html
Matt Secoske wrote:> > > On 2/4/06, *Tom Mornini* <tmornini@infomania.com > <mailto:tmornini@infomania.com>> wrote: > > On Feb 3, 2006, at 10:16 PM, Matt Secoske wrote: > > >> i.e. a typical CMS system such as wordpress that stores the html from >> the pages in a database. I have found a page on the the rails wiki >> http://wiki.rubyonrails.org/rails/pages/HowToRunAnActionBeforeRoutes ) >> that seems to be what I want, but lacking a few details (to me, >> anyway) . > > > ...makes me think you''re looking for something like this: > > class DynamicController < ApplicationController > def show > @code = DynamicContent.find (:id) > end > end > > In the view: > > <div> > <%= @code -%> > </div> > > > Yes, I am definetly looking for the DynamicController version... In > fact, my code is very similar to what you have here. My question is how > do you tie this into rails such that it will be checked at some point in > the rails dispatched request in a seamless manner. i.e. if a view does > not exist for http://domain/controller/action then it calls my > controller with the uri and allows me a chance to still display something. > > I have been tinkering with routes.rb, and am able to get that to > /sometimes/ work. Any tips or explanations on how I can do this would > be greatly appreciated. >I did something similar just recently. I wanted to use a URL like ''http://app/static/<code>'' to access ether a <code>.rhtml file or a <code>.jpg or <code>.png file. I made a controller, app/controllers/static_controller.rb ---- start ----- class StaticController < ApplicationController def method_missing(action_name) $code = action_name.to_s if (File.exist? (@request.env()["DOCUMENT_ROOT"] + "../app/views/static/" + $code + ".rhtml")) then render :action => action_name.to_s elsif (File.exist? (@request.env()["DOCUMENT_ROOT"] + "images/" + $code + ".png")) then $type = "png" render :action => ''picture'' elsif (File.exist? (@request.env()["DOCUMENT_ROOT"] + "images/" + $code + ".jpg")) then $type = "jpg" render :action => ''picture'' else render :action => ''notfound'' end end def picture end def notfound end end ---- end ----- I then created the files app/views/layouts/static.rhtml app/views/static/picture.rhtml app/views/static/notfound.rhtml and some content files app/views/static/<code>.rhtml In the method_missing method you should be able to do a <Controller>.find() call to see if there is dynamic content for a code then call a "render :action => ''dynamic''" to show the dynamic code. Hope this helps. Regards Neil.> Thanks!! > -- > Matt Secoske > http://www.secosoft.net <http://www.secosoft.net> > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Still old, but maybe some other wanted a solution for it, which respons to "dynamic loading view from db" class RouteController < ApplicationController def index @test = "asd" render_layout(1) end private def render_layout(id) render :inline => Page.find_by_id(id).layout.html end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---