Hi all, I''m a relative Rails Noob developing a CMS using rails. I have designed it so that all the public urls are created using an admin tool and stored in a database. I then want to use routes to direct the visitor to the appropriate action of a single controller. The way I see it there are three ways of doing this: 1. Use components - I''d rather not as they are slow and dont really represent what I am trying to do 2. Somehow extract the id of the page using the path from the database within routes.rb, use that to get the appropriate action - I cant figure out how to do this in routes.rb 3. Redirect to a single action which can then point to another action - Sort of what I''m already doing but as far as I know there is no way for a rails action to ''render'' another action Here is the route I am using: <code> map.connect ''*path'', :controller => "public", :action => "page" </code> And here is the page action in PublicController: <code> def page @page = Page.find_from_path(params[:path]) render :action => @page.template, :layout => @page.layout end </code> As you can see I would like to define the template and the layout (actually should be the action) in the database but I just cant work out a way to do it. I have spent a long time trawling the web for a possible solution but have found nothing so far. If anyone could help come up with a solution in any way I would be immensely grateful. Regards Paul Odeon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can do: render :template => @page.template Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
paulodeon-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Jan-31 12:56 UTC
Re: Dynamic (database driven) Routes Problems
As far as I know this will just render the template file as is without calling the action. I really need to call the action. Are you sure this will work? On Jan 31, 12:38 pm, "Steve Bartholomew" <s...-LWB5c3/XHbdBDgjK7y7TUQ@public.gmane.org> wrote:> You can do: > render :template => @page.template > > Steve--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> As far as I know this will just render the template file as is without > calling the action. I really need to call the action.Hmm.. ok. You can use send() to call the action, then use render to render the actual template: # run the template method send(@page.template) # render the page with the template render :template => @page.template However, although I don''t know the application you''re developing, I would suggest that you think about whether or not you can use other methods to achieve this. If you have template specific variables that are set in the controller actions, see if you can use helpers instead. Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
paulodeon-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Jan-31 14:36 UTC
Re: Dynamic (database driven) Routes Problems
Ok, so you can use send() to call another action within the same controller? Interesting.. The problem I have is that the application has to refer to the database to know which url maps to which action. I am currently investigating extending the routing to achieve this but I will investigate the send method. Thanks for your help with this Steve... On Jan 31, 1:17 pm, "Steve Bartholomew" <s...-LWB5c3/XHbdBDgjK7y7TUQ@public.gmane.org> wrote:> > As far as I know this will just render the template file as is without > > calling the action. I really need to call the action. > > Hmm.. ok. You can use send() to call the action, then use render to > render the actual template: > > # run the template method > send(@page.template) > > # render the page with the template > render :template => @page.template > > However, although I don''t know the application you''re developing, I > would suggest that you think about whether or not you can use other > methods to achieve this. If you have template specific variables that > are set in the controller actions, see if you can use helpers instead. > > Steve--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Ok, so you can use send() to call another action within the same > controller? Interesting..Yeah - controllers are just Ruby classes and actions are just methods. my_class.send("my_method") will call ''my_method'' on ''my_class''.> The problem I have is that the application has to refer to the > database to know which url maps to which action. I am currently > investigating extending the routing to achieve this but I will > investigate the send method.What''s wrong with the method you were using? i.e. load the page from the *route and use the data from that to call the correct template. I think you may be in danger of overcomplicating things. Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
paulodeon-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Jan-31 17:22 UTC
Re: Dynamic (database driven) Routes Problems
Steve, I''ve managed to get the send method working after a bit of trial and error. I discovered that you have to do a "return false" in the Controller method doing the send call. While this isnt a perfect solution (I still think it should be handled in the routes) Its not bad at all and it lets me get on with coding. Just to clarify, I needed to be able to store the action in the database, not just the template...that was the problem I was having. Thanks again for your help Paul On Jan 31, 3:06 pm, "Steve Bartholomew" <s...-LWB5c3/XHbdBDgjK7y7TUQ@public.gmane.org> wrote:> > Ok, so you can use send() to call another action within the same > > controller? Interesting.. > > Yeah - controllers are just Ruby classes and actions are just > methods. my_class.send("my_method") will call ''my_method'' on > ''my_class''. > > > The problem I have is that the application has to refer to the > > database to know which url maps to which action. I am currently > > investigating extending the routing to achieve this but I will > > investigate the send method. > > What''s wrong with the method you were using? i.e. load the page from > the *route and use the data from that to call the correct template. I > think you may be in danger of overcomplicating things. > > Steve--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---