0
我有這種形式:減少在軌URL長度
<h1> Global data management </h1> </br> </br>
<h2>Enter the conditions and click "find" option to search for users based on conditions. </br> Or click the "List" option to list all the data. </h2>
</br></br></br>
<%= form_for(:find_field, url: find_field_path , method: :get) do |f| %>
<div class="row">
<div class="span8 offset1">
<div class = "row">
<div class = "span4">
<div class="field">
<%= f.label :data_type_choice, "Data type" %>
<%= f.select :data_type_choice, [["all","all"],["2D","2D"],["3D","3D"],["2D3C","2D3C"],["3D3C","3D3C"]] , :name => nil%>
</div>
</br></br>
<h3> COMPLETED WITHIN </h3>:</br>
<div class="field">
<%= f.label :from_date_choice , "From date " %>
<%= f.date_select :from_date_choice , :name => nil%>
</div>
</div>
<div class = "span4">
<div class="field">
<%= f.label :basin_choice, "Basin" %>
<%= f.select :basin_choice, [["all","all"],["Cauvery","Cauvery"],["KG-PG","KG-PG"],["others","others"]] , :name => nil %>
</div>
</br></br>
<h3> </h3>
<div class="field">
<%= f.label :to_date_choice , "To date " %>
<%= f.date_select :to_date_choice , :name => nil %>
</div>
</div>
</div>
</br></br>
<%= f.submit " Search ", class: "btn btn-large btn-primary" %>
</div>
</div>
<% end %>
一切完美,所有的參數都正確傳遞等,但在我嘗試顯示的結果來看,我得到一個巨大的網址一樣所以:在這個railscast 顯示:「名稱=>無」爲什麼會這樣,我怎麼能減少URL大小隻是「HTTP://本地主機:3000 /全球
http://localhost:3000/global/data/find?utf8=%E2%9C%93&find_field%5Bdata_type_choice%5D=2D&find_field%5Bfrom_date_choice%281i%29%5D=2012&find_field%5Bfrom_date_choice%282i%29%5D=7&find_field%5Bfrom_date_choice%283i%29%5D=9&find_field%5Bbasin_choice%5D=KG-PG&find_field%5Bto_date_choice%281i%29%5D=2012&find_field%5Bto_date_choice%282i%29%5D=7&find_field%5Bto_date_choice%283i%29%5D=9&commit=++Search++
香港專業教育學院使用嘗試/ data/find「?
編輯:
這是fields_controller我find方法:
def find
@data_type_choice = params[:find_field][:data_type_choice]
@basin_choice = params[:find_field][:basin_choice]
@from_date_choice = params[:find_field][:from_date_choice]
@to_date_choice = params[:find_field][:to_date_choice]
end
我也想展示的形式通過find.html.erb像這樣輸入的數據:
<h1><%= @data_type_choice %> dsfgdfsg</h1>
如果我使它成爲一個post請求,erb不會被渲染!我能做什麼?
謝謝:)
我編輯了我的問題,請告訴我如何處理該問題。 – viswa 2012-07-09 10:28:12
調用函數'find'嗎?或者你得到模板丟失的錯誤? – 2012-07-09 10:33:00
好吧,我做了它的工作,不知何故,只是f.submit使它調用字段#create:/。但是當我刪除它並添加了一個:<%= button_to「search」,find_field_path%>,一切都神奇地工作!你知道爲什麼發生了嗎? ñ感謝您的幫助:) – viswa 2012-07-09 11:03:54