Ruby on rails Ruby:如果为“则使用f.select或f.text”字段;其他";在f中选择

Ruby on rails Ruby:如果为“则使用f.select或f.text”字段;其他";在f中选择,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,我需要ruby从f.select或f.text_字段中获取值,如果在select表单中选择了“other”。这怎么可能? 他认为: <div class="field"> Parent</br> <% f.label :parent1 %> <%= select("jobs","parent1_id",["None","8.5x11","shells"]) %> Other: <% f.label :parent2 %&g

我需要ruby从f.select或f.text_字段中获取值,如果在select表单中选择了“other”。这怎么可能? 他认为:

<div class="field">
  Parent</br>
  <% f.label :parent1 %>
  <%= select("jobs","parent1_id",["None","8.5x11","shells"]) %>
  Other:
  <% f.label :parent2 %>
  <%= text_field("jobs","parent2_id") %>
</div>

解决此问题的最简单方法是在select中使用
{:include_blank=>“none”}
,并在控制器中检查其参数是否为null,如果为null,则使用其他参数


我个人如何使用它:
您能详细说明如何做,或者将我链接到一个资源来解释它吗?我对rails非常陌生,时间有限。更新了我的答案,它使用了collection\u select,但它们很相似。如果有帮助,请告诉我。很抱歉再次打扰您,您的文本字段看起来如何?与普通文本字段完全相同,其参数设置为option2\u id选择集合的第一个参数“thing”到底是什么?
def create
  @job = Job.new(params[:job])

    if params[:parent1_id] == "None" #params[:option1_id].nil? #params.has_key?(:option1_id) #Take your pick
        @job.parent = params[:parent2_id]
    else
        @job.parent = params[:parent1_id]
    end

  respond_to do |format|

    if @job.save
      format.html { redirect_to @job, :notice => 'Job was successfully created.' }
      format.json { render :json => @job, :status => :created, :location => @job }
    else
      format.html { render :action => "new" }
      format.json { render :json => @job.errors, :status => :unprocessable_entity }
    end
  end
end
<%= form_for @thing, :html => { :class => 'form-horizontal' } do |f| %>
  .....
<div class="field">
  <%= f.label :name %><br />
  <%= select_tag "count", "<option>None</option><option>8.5x11</option><option>shells</option>".html_safe %>
</div>
<div class="field">
  <%= f.label :name %><br />
  <%= text_field_tag "users" %>
</div>
  ........
    <div class="form-actions">
      <%= f.submit "Submit", :class => 'btn btn-primary' %>
  .......
    </div>
<% end %>
def create
.......
  if params[:option1_id] == "" #params[:option1_id].nil? #params.has_key?(:option1_id) #Take your pick
    @thing.attribute = params[:option2_id]
  else
    @thing.attribute = params[:option1_id]
  else
end