【发布时间】:2012-08-17 10:04:42
【问题描述】:
我有一个表格来收集生成报告的参数。我知道 formtastic 是为模型设计的,但我需要在这里使用它,因为表单位于 activeadmin 页面中。
一切正常,但我无法为选择设置默认值。我愿意实施“卑鄙的黑客”来使其正常工作。我不想实现一个假模型 只是为了在表单上设置默认值。
表单代码如下所示
<%= semantic_form_for "report", :url => report_admin_payments_path do |f| %>
<%= f.inputs do %>
<%= f.input :report_type, :as => :select, :collection => report_types, :input_html => {:style => "width:180px"} %>
<%= f.input :start_date, :as => :string, :input_html => {:class => 'datepicker', :style => "width:60px", :value => 1.month.ago.strftime("%Y-%m-%d")} %>
<%= f.input :end_date, :as => :string, :input_html => {:class => 'datepicker', :style => "width:60px", :value => Time.zone.now.strftime("%Y-%m-%d")} %>
<%= f.input :country, :as => :select, :collection => locales, :input_html => {:style => "width:180px"}%>
<% end %>
<%= f.actions :submit %>
<% end %>
提前致谢,
马特
【问题讨论】:
-
这看起来像一个简洁的方法railscasts.com/episodes/219-active-model
标签: ruby-on-rails-3 formtastic