Hi, Say in mywebsite i have 20 pages which all use the same method to get some data from a model. So for example i have the follwoing pages(aboutus,news, resources), inside my site i would have the following to provide a link which uses the method page and passes the paramter pagename. <%= link_to ''aboutus'', :action => ''page'', :pagename => ''aboutus'' %> <%= link_to ''news'', :action => ''page'', :pagename => ''news'' %> <%= link_to ''resources'', :action => ''page'', :pagename => ''resources'' %> def page @information => Page.getinfo(params[:pagename]) render :action => :pagename end What the above code does is calls the same method page, gets some information from the pages table about that page and then displays the appropriate page with the information from the database. My problem is, say i give this link to someone www.mysite.com/aboutus this is not going to call the page method and get the appropriate information and then display the page, it will try open up the page without the information from the model and cause an error. This will look for a method called aboutus which doesnt exist. Now i cant create a different method for each page because pages are going to be added to this site quite regularily so for each new page created i would have to amend the controller with a method for each new page added which isnt what i would like. Is it somehow possible to tell request like www.mysite.com/aboutus to access the page method and use the aboutus on the end of the link to get the appropriate information and show the correct page? The only possible way i can think off is to have each link access the page method like www.mysite.com/page(pagenameparameter) and use the paramater as ameans of deciding which page to view, this is not an ideal solution. I hope the problem is explained ok and if anyone has any suggestions i would be gratefull in their response. JB -- 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 -~----------~----~----~----~------~----~------~--~---
You''ll want to research rails routing. The default route is of the form map.connect '':controller/:action/:id'' So right now the only way to display your pages based on the way you''ve setup your controller is http://www.mysite.com/mycontroller/page/?page=aboutus # => goes to aboutus page --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brian Gibson wrote:> You''ll want to research rails routing. The default route is of the > form > > map.connect '':controller/:action/:id'' > > So right now the only way to display your pages based on the way you''ve > setup your controller is > > http://www.mysite.com/mycontroller/page/?page=aboutus # => goes to > aboutus pageThanks Brain, will read up on routing and decide the best approach. Yes at the moment i have the follwoing below and although i ive seen a lot uglier URLs in the past hopefully there is a cleaner way of doing it using the routing. http://www.mysite.com/mycontroller/page/?page=aboutus http://www.mysite.com/mycontroller/page/?page=resources http://www.mysite.com/mycontroller/page/?page=news -- 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 -~----------~----~----~----~------~----~------~--~---
On 22 Sep 2006, at 20:54, John Butler wrote:> Yes at the moment i have the follwoing below and although i ive seen a > lot uglier URLs in the past hopefully there is a cleaner way of > doing it > using the routing. > > http://www.mysite.com/mycontroller/page/?page=aboutus > http://www.mysite.com/mycontroller/page/?page=resources > http://www.mysite.com/mycontroller/page/?page=newsYou may like to look at this article which describes how to set up routes for the ''flat'' pages on your website, which sounds like what you want to do: http://www.paulsturgess.co.uk/articles/show/27 Your URLs will look like: http://www.mysite.com/aboutus http://www.mysite.com/resources .... I didn''t see the original post so apologies if this is not what you are after. Regards, Andy Stewart --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---