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
<%= link_to ‘aboutus’, :action => ‘page’, :pagename => ‘aboutus’ %>
<%= link_to ‘news’, :action => ‘page’, :pagename => ‘news’ %>
<%= link_to ‘resources’, :action => ‘page’, :pagename => ‘resources’ %>
@information => Page.getinfo(params[:pagename])
render :action => :pagename
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
I hope the problem is explained ok and if anyone has any suggestions i
would be gratefull in their response.