這個是我 view 的頁面 具體的程式碼如下:
<% content_for :header do %>
<script>
jQuery(function($){
//alert("ewe");
$(".date_pick").datepicker();
})
</script>
<% end %>
<form action="show_money" methods="get">
<input type="text" name="start_at" value="<%= (Time.now - 1.year).strftime("%Y/%m/%d") %>" class="date_pick"/>
<input type="text" name="end_at" value="<%= Time.now.strftime("%Y/%m/%d") %>" class="date_pick"/>
<select name="level">
<% @level.each do |level| %>
<option value="<%= level[1] %>"><%= level[0] %></option>
<% end %>
</select>
<select name="howuknowu">
<% @howuknowu.each do |howuknowu| %>
<option value="<%= howuknowu[1] %>"><%= howuknowu[0] %></option>
<% end %>
</select>
<select name="whylearn">
<% @whylearn.each do |whylearn| %>
<option value="<%= whylearn[1] %>"><%= whylearn[0] %></option>
<% end %>
</select>
<input type="submit" value="send"/>
</form>
我有請教其它的程式設計師,他大概說了底下的作法,說是那樣就可以在 view 產生一個 陣列,當參數傳給下一個頁面用。但我無法理解具體的作法該是怎麼樣子
form_tag do
text_field_tag 'xxx_ids[] x 10'
end
接下來是我控制器裏的寫法 #加入學歷的選項
def money
@level = Incomelevel.all.map{|im|[im.reason_desc , im.id]} #test ok by rails c
@howuknowu = Howuknowu.all.map{|sh|[sh.reason_desc , sh.id]} #test ok by rails c
@whylearn = Whylearn.all.map{|sw|[sw.reason_desc , sw.id]} #test ok by rails c
render :layout =>"test_layout"
end
def show_money
start_at = Time.parse(params[:start_at])
end_at = Time.parse(params[:end_at])
level = params[:level].to_i
howuknowu = params[:howuknowu].to_i
whylearn = params[:whylearn].to_i
@income_ids = params['level[][]'].map{|i|i.to_i > 0 ? i.to_i : nil}.compact
@howuknowus_ids = params['howuknowu[][]'].map{|i|i.to_i > 0 ? i.to_i : nil}.compact
@whyulearn_ids = params['Whylearn[][]'].map{|i|i.to_i > 0 ? i.to_i : nil}.compact
@students = Student.from('students AS s').joins("
INNER JOIN student_incomes AS si ON si.student_id = s.id AND si.income_id IN (#{@income_ids.join(',')})
INNER JOIN student_howyouknowus AS sh ON sh.student_id = s.id AND sh.howyouknowus_id IN (#{@howuknowus_ids.join(',')})
INNER JOIN student_whyyoulearn AS sw ON sw.student_id = s.id AND sw.whyyoulearn_id IN (#{@whyulearn_ids.join(',')})
INNER JOIN students ON (students.id = si.student_id AND
students.created_at BETWEEN
DATE('#{start_at.strftime("%Y/%m/%d")}') AND
DATE('#{end_at.strftime("%Y/%m/%d")}'))
")
執行的話就噴出底下的錯誤訊息,求高手指點