2

如果我有一个带有一个文本字段的表单,我可以以某种方式访问​​ url

/some/url/contents_of_form

就像当用户在 text_field 中输入“google.com”并按“提交”时我进行域搜索一样,它会转到/domain/google.com然后路由分派 google.com 和………… whois 显示给用户

4

2 回答 2

2

在您放置的 routes.rb 文件中

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

在 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
于 2012-04-18T19:17:56.990 回答
1

您可以从 javascript 更改 window.location.href:http ://www.ezineasp.net/post/Javascript-Window-Location-Href-URL.aspx

于 2012-04-18T18:32:54.727 回答