作者dickcd (迪克)
看板Ruby
标题[问题] 关於date格式的query
时间Sun Oct 21 22:37:12 2007
目前的设计是这样
+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
1F:推 deduce:建议不要用 date=#{query} 还是用我在754篇讲的写法吧 10/21 23:04
2F:推 dickcd:抱歉,一时就忘记了,等等改过来先! 10/21 23:25
3F:推 shelary:我都用最丫呆的方法 d=query['(1i)']+'-'+query['(2i)']+ 10/22 00:05
4F:→ shelary: '-' + query['(3i)'] 10/22 00:07
5F:→ shelary:然後 :conditions => ["date=?", d] 10/22 00:08
6F:推 shelary:不过你的 date_select 'q', nil 这样用 nil 很怪耶 10/22 00:10