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

  • SEARCH
  • Home
  • 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 3278184
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:27:11+00:00 2026-05-17T19:27:11+00:00

I have a complex form (like Ryan B’s Complex Form Railscasts) where I have

  • 0

I have a complex form (like Ryan B’s Complex Form Railscasts) where I have a few levels of database tables being altered at the same time.

The code for this dropdown box works in that it delivers the correct integer to the database. But, despite numerous attempts I cannot get it to correctly reflect the database’s CURRENT value. How can I sort out this code?

<%= o.select :weighting, options_for_select([
  ["Correct", "4", {:class=>"bold"}],
  ["Good", "3"],
  ["Average", "2"],
  ["Poor", "1"], 
  ["Incorrect", "0", {:class=>"bold"}] ], :weighting), {},
  html_options = {:class => "listBox", :style=>"float:left;"} %>

Thanks.

  • 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-05-17T19:27:12+00:00Added an answer on May 17, 2026 at 7:27 pm

    You’re on the right track, but not quite there.

    While the final argument to options_for_select should be the value of the selected option. The value you supply :weighting is a symbol that does not match the value of any of your given options.

    You will need to give the actual value. If you used an instance object to build the form as in

    <%form_for @whatever do |o|%>
    ...
    

    You can simply used @whatever.weighting.to_s as in:

    <%= o.select :weighting, options_for_select([
      ["Correct", "4", {:class=>"bold"}],
      ["Good", "3"],
      ["Average", "2"],
      ["Poor", "1"], 
      ["Incorrect", "0", {:class=>"bold"}] ], @whatever.weighting.to_s), {},
      html_options = {:class => "listBox", :style=>"float:left;"} %>
    

    Otherwise, there’s a way to get the object off the form block variable o. But that’s messing with internals which may change with an upgrade.

    Edit: In the case where you’re working with fields for and multiple partials, you can get the particular object off of the form builder block variable.with the object accessor.

    Reusing the above example something like this to use the current weighting of each child instance in that instance’s section of the form.

    <% form_for @parent do |p| %>
      ...
      <% p.fields_for :children do |c| %>
      ...
      <%= c.select :weighting, options_for_select([
          ["Correct", "4", {:class=>"bold"}],
          ["Good", "3"],
          ["Average", "2"],
          ["Poor", "1"], 
          ["Incorrect", "0", {:class=>"bold"}] ], c.object.weighting.to_s), {},
          html_options = {:class => "listBox", :style=>"float:left;"} %>
      ...
      <% end %>
    <% end %>
    

    This can also be used in partials.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well i have a complex form view model like this : public class TransactionFormViewModel
I have two very complex queries that are displayed on the same form and
I have a complex command that I'd like to make a shell/bash script of.
I have a complex form for a model Schedule that belongs to a parent
I have a complex form in Ruby on Rails 2.3.5, here's the structure for
I have a complex form that has a static section and one that can
I have a pretty complex form with lots of inputs and validators. For the
I have a complex input form within a PHP based web application. To structure
I have a fairly complex html form enhanced via jquery. It has multiple tabs,
I have been working on quite a complex accordion/form recently and have a select

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.