How to create custom ruby ​​redirection on rails?

I created a model called LandingPage, and the current route looks something like this:

www.domain.com/landing_pages/1

Or something like that. I will have several of them, therefore destination_page, where id = 1 ... n.

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

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

subdomian.domain.com/superbowl 

who allowed

www.domain.com/landing_pages/1/

How should I do it? Each landing_page has a “shortname” attribute associated with its specific landing_page.

I'm on Rails 2.3.8. My hunch is in routes to scroll through available short words, 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
+3
1

, RedirectsController, routes.rb :

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

, . RedirectsController show :

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

, www.domain.com/landing_pages/1/, , showingPagesController:

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

, , , , , 2.3.8. , , , .

, subdomain-fu, . https://github.com/mbleigh/subdomain-fu. , , .

0

All Articles