2012-10-05 2 views
-1

I'am을 저장하고 내가 선택한 업데이트 값은 내가 업데이트 할 때 레일 <code>select_tag</code>를 사용하여 select_tag 값을

를 저장되지 않은 태그 값이 첫 번째 옵션을 얻을

edit.html.erb

<%= form_for(@name) do |f| %> 

    <div class="field"> 
    <%= f.label :name %><br /> 
    <%= f.text_field :name %> 
    </div> 

    <div class="field"> 
    <%= f.label :lname%><br /> 
    <%= f.text_field :lname%> 
    </div> 

    <div class="field"> 
    <%= f.label :tag %><br /> 
    <%= f.select :tag, "<option>1</option><option>2</option><option>3</option><option>4</option>".html_safe %> 
    </div> 

    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

솔루션

<%= f.collection_select(:tag, [1,2], :to_i, :to_s, :prompt => 'Categories') %> 
+2

코드 및 정보를 더 추가하십시오. – 99miles

답변

0

솔루션

<%= f.collection_select(:tag, [1,2], :to_i, :to_s, :prompt => 'Categories') %> 
0

이 링크에서 선택 태그를 사용하려고

select_tag

<%= select_tag "tag", "<option>1</option><option>2</option>" %> 
1

어쩌면?

= f.select :tag, (1..4).to_a, :prompt => '---' 
관련 문제