我有一个formtastic表单来收集报告生成的参数。我知道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 %>
提前致谢,
马特
答案 0 :(得分:0)
这类或类似的东西应该满足你的需求。
class LightModel
# Subclass this for a model that looks like an ar model but has no persistence
# good for formtastic forms
include ActiveModel::Naming
include ActiveModel::Validations
def initialize(attributes = {})
@attributes = attributes
end
# read only atm
def method_missing(m, *args, &block)
@attributes[m]
end
end
谢谢,
马特