[問題] 關於date格式的query

看板Ruby作者 (迪克)時間17年前 (2007/10/21 14:37), 編輯推噓4(402)
留言6則, 3人參與, 最新討論串1/1
目前的設計是這樣 +index.rhtml <%= start_form_tag :action => 'search'%> <p><label for="record_date">日期</label><br/> <%= date_select 'q', nil %> <%= submit_tag 'Search' %></form> <%= end_form_tag %> +records_controller.rb def search query = params[:q] @record = Record.find(:all, :conditions => "date=#{query}" ) end 可是這樣會出現 undefined method `tostring' for {"(3i)"=>"21", "(1i)"=>"2007", "(2i)"=>"10"}:HashWithIndifferentAccess 的錯誤,應該是要轉換格式吧? 麻煩大家了,謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.167.165.109

10/21 23:04, , 1F
建議不要用 date=#{query} 還是用我在754篇講的寫法吧
10/21 23:04, 1F

10/21 23:25, , 2F
抱歉,一時就忘記了,等等改過來先!
10/21 23:25, 2F

10/22 00:05, , 3F
我都用最丫呆的方法 d=query['(1i)']+'-'+query['(2i)']+
10/22 00:05, 3F

10/22 00:07, , 4F
'-' + query['(3i)']
10/22 00:07, 4F

10/22 00:08, , 5F
然後 :conditions => ["date=?", d]
10/22 00:08, 5F

10/22 00:10, , 6F
不過你的 date_select 'q', nil 這樣用 nil 很怪耶
10/22 00:10, 6F
文章代碼(AID): #176sGPfG (Ruby)
文章代碼(AID): #176sGPfG (Ruby)