2012-07-09 95 views
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>&nbsp</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不会被渲染!我能做什么?

谢谢:)

回答

2

只需将您的方法从GET更改为POST,并相应地更改路由。

尝试

<%= form_for(:find_field, url: find_field_path , method: :post) do |f| %> 

你的路由文件应符合的要求为POST。

+0

我编辑了我的问题,请告诉我如何处理该问题。 – viswa 2012-07-09 10:28:12

+0

调用函数'find'吗?或者你得到模板丢失的错误? – 2012-07-09 10:33:00

+0

好吧,我做了它的工作,不知何故,只是f.submit使它调用字段#create:/。但是当我删除它并添加了一个:<%= button_to“search”,find_field_path%>,一切都神奇地工作!你知道为什么发生了吗? ñ感谢您的帮助:) – viswa 2012-07-09 11:03:54