2013-07-03 22 views
1

我是Ruby/Rails的新手,我試圖創建一個基本網站。如何從text_field將文本發送到Ruby on Rails中的URL參數?

我想有一個text_field讓用戶輸入消息。然後,用戶可以點擊一個提交按鈕。我想url是這樣的:

.../foo?message="Whatever the user typed in" 

目前我有<%= link_to "Submit", foo_path(:message => "hello") %>。這可以使參數成爲「hello」,但是如何使用text_field中的文本呢?

我很困惑,因爲text_field需要object_name和方法參數,但我不需要對象或方法。

回答

1

你只需要使用文本框形成和get method

<%= form_tag ..... , :method => :get do |f| %> 
    <%= text_field_tag %> 
<% end %> 

就像谷歌

<form id="gbqf" name="gbqf" method="get" action="/search" class="gbes"> 
    <input type="text" value="" autocomplete="off" name="q" id="gbqfq"> 
</form> 
相關問題