1

次のような単純なフォームがあります。

 <%= simple_form_for @study,:url => studies_path, :html => { :class => 'form-horizontal' } do |f| %>
    <%= f.input :category, :collection => @categories, :label => "Category", :selected => @categories.first %>
  <%= f.button :submit, t('add_form'),:class => 'btn-primary' %>

ビジュアルシュガーに過ぎない形で新しいフィールドを追加したいです。:category フィールドを動的に変更するためのヘルパーになります。

それ、どうやったら出来るの?

4

1 に答える 1

0

text_field_tagまたはその他のヘルパーを使用_tagして、モデルの特定の属性にアタッチせずにフォーム要素を生成します。

<%= simple_form_for @study,:url => studies_path, :html => { :class => 'form-horizontal' } do |f| %>
  <%= f.input :category, :collection => @categories, :label => "Category", :selected => @categories.first %>
  <%= text_field_tag :blah %>
  <%= f.button :submit, t('add_form'),:class => 'btn-primary' %>
<% end %>
于 2012-06-29T15:13:37.460 に答える