Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7714779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:13:01+00:00 2026-06-01T02:13:01+00:00

I need ruby to either take the value from an f.select or an f.text_field

  • 0

I need ruby to either take the value from an f.select or an f.text_field if ‘other’ is chosen in the select form. how is this possible?
in the view:

<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>

in the controller:

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:13:03+00:00Added an answer on June 1, 2026 at 2:13 am

    The simplest way around the problem would be to use {:include_blank => "none"} in the select, and check if its parameter is null in the controller, if it is then use the other parameter.


    How I personally used it:

    <%= 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 %>
    

    Note collection_select is a variation on select where I pass in another model’s items.

    In the controller:

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a simple library in Ruby and need to use this in
I need to do some communications over a serial port in Ruby. From my
I need a client side API in either Java or Ruby. I would much
I read about many CSS related languages and tools which need ruby. What is
I need to write a little ruby function that does word wrapping. I have
I need to run a standalone ruby script as Unix (linux) daemon. After running
Using Your Ruby Gem(s) You will need to add /home/username/ruby/gems to the include path.
I need to be able to determine a systems maximum integer in Ruby. Anybody
I need some examples of implementing curry function in ruby(1.8.6 or 1.8.7 not 1.9).
I need to implement fine-grained access control in a Ruby on Rails app. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.