Rails simple_form 非模型属性的输入框生成问题

evan · October 29, 2012 · Last by zhangyuan replied at October 29, 2012 · 2282 hits

后台想接受一个字段在 model 属性中没有,但是想用 simple_form 的风格,只能这样吗?

<div class="clearfix string">
      <label class="string">次数</label>
      <div class="input"><%= text_field_tag :times, params[:times] %></div>
    </div>

或者在 model 中写一个 attr_acceesor :times, 再用:

<%= f.input :times %>

有没有更好的办法?

试试这样

<%= f.input :times do %>
  <%= f.text_field :times %>
<% end -%>
You need to Sign in before reply, if you don't have an account, please Sign up first.