简体   繁体   中英

Rails3 - routing: How do you create a root path for a database-driven item?

Background info

  • I have an app where users can make microsites ala http://myname.the_app.com .
  • Microsite has_many :pages
  • Each Microsite belongs_to :landing_page (which is a Page) that determines where the visitor is fowarded when they view the site. Right now the app does a redirect_to @microsite.landing_page . The visitor then sees a url like so: `http://myname.the_app.com/pages/id

How can I render the landing page but keep the root path? I want to be able to see the "about page" but with the url http://myname.the_app.com .

An option

Here's an option: have a home_controller#index action that instantiates all the page variables it needs. However ... I'm holding this off because what if I have more than page? What if I want the landing_page to be something else in the future, like a contact_form located at `/contact_forms/id?

Thanks!

Perhaps render :template => "pages/#{whatever_id}" might solve your problem. Just replace your redirect_to with the render...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM