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 8767913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:56:17+00:00 2026-06-13T16:56:17+00:00

I have a form where based on the value selected by the user in

  • 0

I have a form where based on the value selected by the user in a drop down list, the rest of the form is displayed via a partial.

Model:

Book has many supplierdetails
Supplierdetails belongs to Book

form code

<% fields_for @book do |f| %>


 Catalogue Number: <%= f.text_field :BK_CAT_NUM %>

  <% f.fields_for :supplierdetails do |builder| %>
   Supplier Type:
    <%= builder.select(:SUP_TYPE, 
         [['A', 'A'],
          ['B', 'B'],
        ],{ :prompt => "Please select"}       
      ) %>


    <%= observe_field("book_supplierdetails_attributes_0_SUP_TYPE", 
      :url => { :controller => 'books', :action => :display_ab_details },
      :with => "'id='+value") %>

    <div id="div1">  </div>



  <% end %>
<% end %>

controller method

  def display_ab_details
    supplier_type = params[:id]
    if supplier_type == "A"
      render :update do |page|
        page['div1'].replace_html :partial => 'books/test_partial'
      end
    end
  end

books/_test_partial.html.erb

Production Method: </label> <%= builder.select(:SUP_PROD_METHOD, [
        ['prod_1', 'prod_1'],
        ['prod_2', 'prod_2'],
      ],{ :prompt => "Please select"}
    ) %>

The partial is not displayed and I believe it is because of the form object.

If ‘books/_test_partial.html.erb’ contains plain text, it is displayed correcly.

How do I deal with form object when rendering partial via rjs?

  • 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-13T16:56:18+00:00Added an answer on June 13, 2026 at 4:56 pm

    I don’t have an actual answer for your question, but since RJS is not in Rails anymore since v3.1, you’re better off jumping the bandwagon and using unobtrusive javascript for things like this, as it is now the preferred way to do things like this. It will be easier to get help as well, since most Rails developers don’t use RJS nowadays (actually, not a lot of people used it before either).

    Some information on that can be found here: http://wowkhmer.com/2011/09/19/unobtrusive-ajax-with-rails-31/

    Also, what you are doing probably doesn’t work because you’re trying to use builder in the partial. You can’t do that. You need to either use fields_for or simply output the inputs HTML yourself, but be careful to provide the correct name for the inputs. Also I’m pretty sure if you look into your server log you will see an error on that line where you’re trying to use builder. There is absolutely no way in Rails to use the builder of the original form in a partial that is being rendered later via an AJAX request.

    There is also a Railscasts where Ryan does something similar to what you’re doing, but he is not using RJS. I believe it is this episode or something related to it: http://railscasts.com/episodes/75-complex-forms-part-3

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

Sidebar

Related Questions

I am dynamically generating the form based on the drop down selected. The form
I have setup a form that allows a user to make selections from drop-down
I have a list of Payees in a drop down box on my form.
I have two drop down lists. Second one is populated based on value chosen
I want fill a drop down list based on user selection in another. Can't
I have a form with 2 selects. Based on the value of the first
I have two drop down menus. <form action=form.php class=inputlabels enctype=multipart/form-data id=new_asset method=post> <select id=asset_id
I have a form that contains 5 drop down lists which are created by
I have a form that is populated with dynamic form elements based on a
I have a Tabular type Form based upon a SELECT * FROM table type

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.