Uko
Uko

Reputation: 13386

Send form to a url of its contents

If I have a form with one textfield, can I somehow go to url like

/some/url/contents_of_form

Like if I have a domain search when user enters "google.com" in the text_field and presses "submit" it goes to /domain/google.com and then routes dispatch google.com and ………… the whois is shown to user

Upvotes: 2

Views: 94

Answers (2)

Marlin Pierce
Marlin Pierce

Reputation: 10079

In your routes.rb file you put

resource domain, :only => [] do
  get search_form
  get search
end
match 'domain/:location_name' => 'domains#whois'

In app/controllers/domains_controller.rb

class DomainsController < ApplicationController
  def search_form
    #serve search form with text field.  Text field has name="location"
  end

  def search
    redirect_to "domain/#{params[:location]}"
  end

  def whois
    @location = params[:location]
  end
end

Upvotes: 2

svlada
svlada

Reputation: 3288

You can change window.location.href from javascript: http://www.ezineasp.net/post/Javascript-Window-Location-Href-URL.aspx

Upvotes: 1

Related Questions