Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4035596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:07:05+00:00 2026-05-20T12:07:05+00:00

I have created a model called LandingPage, and the current route is something like:

  • 0

I have created a model called LandingPage, and the current route is something like:

www.domain.com/landing_pages/1

Or something like that. I will have several of these, so landing_page where id = 1…n.

However, when someone creates the landing page, I would like them to be able to define an attribute for the model, such as “superbowl” to redirect to landing_page/1, “nice” to landing_page/2, etc.

This would allow the user to define the landing page as:

subdomian.domain.com/superbowl 

which would resolve to

www.domain.com/landing_pages/1/

How do I do that? Each landing_page has an attribute ‘shortname’ which ties to its specific landing_page.

I am on Rails 2.3.8. My hunch is in the routes to loop through the available shortnames, but not sure.

 8   def show
  9     
 10     @landing_page = LandingPage.where(:name => params[:name]).first
 11     redirect_to landing_page_path(@landing_page)
 12     
 13     #@landing_page = LandingPage.find(params[:id])
 14     @redcloth_landing_page = RedCloth.new(@landing_page.message).to_html
 15     form = "<div id='form'>" << @landing_page.form << "</div>"
 16     
 17     @redcloth_landing_page.gsub!("{Form}",form)
 18     
 19     render :layout => false
 20   end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:07:06+00:00Added an answer on May 20, 2026 at 12:07 pm

    Taking your comments into account, you need a RedirectsController, and in your routes.rb file, you would have:

    map.connect '/:name', :controller => 'redirects', :action => 'show'
    

    You need to make sure that this route comes after your resource routes. In your RedirectsController, the show method would be something like:

    def show
      @landing_page = LandingPage.first(:conditions => {:name => params[:name]})
      redirect_to @landing_page
    end
    

    I’m not sure what you’re trying to achieve at http://www.domain.com/landing_pages/1/, but using your code as an example, you should have the following in your LandingPagesController show action:

    def show
    
      @landing_page = LandingPage.find(params[:id])
      @redcloth_landing_page = RedCloth.new(@landing_page.message).to_html
      form = "<div id='form'>" << @landing_page.form << "</div>"
    
      @redcloth_landing_page.gsub!("{Form}",form)
    
      render :layout => false
    end
    

    However, this solution is not as good as before because, unless I am missing it, I do not know that you can constrain a route to a subdomain in 2.3.8. Without constraining to subdomains, you would have to make sure your users did not use one of your controllers’ names as a landing page word, adding complexity to your program.

    There is a plugin, called subdomain-fu, which should allow you to restrict your routes to a subdomain. The project is located at https://github.com/mbleigh/subdomain-fu. I hope this helps, if not let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have very simple problem. I need to create model, that represent element of
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have created a template for Visual Studio 2008 and it currently shows up
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a C# class file by using a XSD-file as an input.
Is it possible to create/have a non-modal .net OpenFileDialog I have a UI element
I have a GSM modem connected via USB. The modem creates 2 serial ports.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.