Forum: Ruby on Rails Collection_select with optional text box.

6de1f19624f27e2e059e2b511ef4bfe6?d=identicon&s=25 Travis Fantina (tfantina)
on 2016-12-08 19:49
I have a form that prompts a user to select an option from a drop down
selection box.  Ideally I'd like a text box to appear next to the
selection box only if they select "Add new".  I've been able to do this
in the past with the select helper but I haven't been able to get
collection_select to work.

I've tried a few different things but my latest iteration looks like

    <div class="field" >
      <%= f.fields_for :reviews do |c| %>
         <%= c.collection_select(:review, Review.order(:review), :id,
          include_blank: true, :prompt => "add select", :onchange
         <%= c.text_field :review, review: "class-show", style:
"display: none;"%>
      <% end %>

  review-dropdown = function(){
      if(this.value == "Add New") {
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.