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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:54:28+00:00 2026-06-12T23:54:28+00:00

I have a problem refreshing a partial with fields_for inside. Here is the code

  • 0

I have a problem refreshing a partial with fields_for inside.

Here is the code of the partial (‘table_detalle’)

<table class="table">
    <thead>
        <tr>
            <th><%= t('.denominacion') %></th>
            <th><%= t('.cantidad_ingreso') %></th>
            <th><%= t('.importe') %></th>
        </tr>
    </thead>
    <tbody>

        <%= f.fields_for :operacion_detalles do |builder| %>
        <tr>
            <%= render 'table_detalle_operacion', f: builder %>
        </tr>
        <% end unless @operacion.nil? %>

    </tbody>
</table>
<%= content_tag :h3, t('.total', :value=> number_to_currency(@operacion.R_IMPORTE)).html_safe, :class => 'pull-right', style: 'display:inline'  %>

when the user change a value of a combo i would like to refresh the partial above (because the details objects must change and are editable)

Here is the javascript code:

$('#operacion_TIPOVALOR_ID').change(function(){
                      $.ajax({
                      url: '<%= cambiar_tipo_valor_movimientos_path %>',
                      data: {tipo_valor_id: $('#operacion_TIPOVALOR_ID').val()},
                      complete: function(){
                        $('#tipo_valor_loader').css('display','none');
                      },
                      beforeSend: function(){
                        $('#tipo_valor_loader').css('display','inline');
                      },
                      success: null,
                      dataType: 'script'
                    });
            });

the controller code:

def cambiar_tipo_valor
        @operacion = Operacion.new
        denominaciones = TipoValorDenominacion.all_from_tipo_valor params[:tipo_valor_id]
        denominaciones.each do |deno|
            @operacion.operacion_detalles.build :tipo_valor_denominacion => deno, :I_CANTIDAD => 0, :R_IMPORTE => 0
        end
    end

as you can see the “operacion_detalles” change depending on the user selection.

the .js.erb code:

$('#detalle').html('<%= escape_javascript(render :partial => 'table_detalle') %>');

But, i get:

undefined local variable or method `f' for #<#<Class:0x45ae1c8>:0x5062338>

So, i need the f variable to render the partial. Is there any way to emulate the f variable?

Thanks in advance.

  • 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-12T23:54:30+00:00Added an answer on June 12, 2026 at 11:54 pm

    I had no other choice than resolve the problem by hand. What i mean?

    Instead of a field_for => each_with_index:

        <% @operacion.operacion_detalles.each_with_index  do |detalle, index| %>
            <tr>
            <%= render 'table_detalle_operacion',  detalle: detalle, index: index  %>
            </tr>
        <% end -%>
    

    The use the tags helpers like this:

    <td>
        <input type="hidden" value="<%= detalle.tipo_valor_denominacion.R_MULTIPLICADOR %>" class="multiplicador"/>
        <%= hidden_field_tag "operacion[operacion_detalles_attributes][#{index}][TIPOVALORDENO_ID]", detalle.TIPOVALORDENO_ID %>
        <%= detalle.tipo_valor_denominacion.CTIPOVALORDENO %></td>
    <td>
        <%= text_field_tag "operacion[operacion_detalles_attributes][#{index}][I_CANTIDAD]", detalle.I_CANTIDAD %>
        <%= content_tag(:span, detalle.errors[:I_CANTIDAD].join(', '), class: 'help-block') if detalle.errors.has_key? :I_CANTIDAD %>
    </td>
    <td>
        <%= hidden_field_tag "operacion[operacion_detalles_attributes][#{index}][R_IMPORTE]", detalle.R_IMPORTE %>
        <%= content_tag :span, number_to_currency(detalle.R_IMPORTE), class: 'detalle-importe pull-right' %>
        <%= content_tag(:span, detalle.errors[:R_IMPORTE].join(', '), class: 'help-block') if detalle.errors.has_key? :R_IMPORTE %>
    </td>
    

    In this case i had supply the names, so when this code is executed

    $('#detalle').html('<%= escape_javascript(render :partial => 'table_detalle') %>')
    

    It does not need the f variable.

    Hope it helps.

    pd: I know this is not a very good solution but it works.

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

Sidebar

Related Questions

I have a problem with updating/refreshing data in table. I am using DefaultTableModel. Here
I have the problem in refreshing the table. I create the table like this
I have a problem refreshing a ListView. I call my ListView Activity , I
I'm using EJB3 and I have a problem related to refreshing my EntityManager .
I have got a problem here in terminating the threads. The problem is that
I am having a problem with my Listbox not updating/refresing.I have read here that
I have a problem refreshing a DataGridView control after Insert or Update . The
Hi I'm having problem refreshing my listview after Async operation. I have a simplecursoradapter,
I'm refreshing my PHP knowledge and have a problem I can't solve on my
I have a problem with JTable / JScrollPane . My data table is not

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.