将表单发送到其内容的URL

时间:2012-04-18 18:28:57

标签: ruby-on-rails ruby-on-rails-3 forms rest

如果我有一个包含一个文本字段的表单,我可以以某种方式转到像

这样的网址
/some/url/contents_of_form

如果用户在text_field中输入“google.com”并按“提交”时进行域名搜索,则会转到/domain/google.com,然后路由调度google.com和............显示whois用户

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

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

更改window.location.href