2012-04-18 183 views
2

一個URL如果我有一個表格一個文本框,我可以以某種方式去URL像發送形式的內容

/some/url/contents_of_form 

就像如果我有一個域搜索,當用戶在輸入「google.com」在text_field並按下「提交」時,轉到/domain/google.com,然後路線調度google.com和............的WHOIS是顯示給用戶

回答

2

在你把你的routes.rb文件放到

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

在應用程序/控制器/ 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