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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:24:43+00:00 2026-06-13T10:24:43+00:00

I have a question on this: I have a partial named _return_item.html.erb , so

  • 0

I have a question on this:
I have a partial named _return_item.html.erb, so I want to render it repeatedly and dynamically.

<%= f.fields_for :return_items, return_item do |item_form| %>
  some_field_input_for_return_item
<%end%>

The index.html.erb is like this:

<%= form_for(@return_request) do |f| %>
  <div id="contact">
    <!-- some_field_input_for_request_contact_info -->
  </div>
  <div id="itemlist">
    <!-- This part is working-->

    <% @return_request.return_items.each do |item| %>
      <%= render :partial => "return_items/return_items", :locals => {:f => f, :return_item => item}%>
      <!-- I_want_to_append_the_partial_here -->
    <%end%>

  </div>
  <%= button_tag("Add New Item", :class=>"addItem" )%>
<%end%>

<script>
  $(document).ready( function () {
    $( '.addItem' ).click(function () {
      $.ajax({
        url: "return_requests/request_new_item",
        data: {
               item_num: ($( '#itemlist' ).children().length)
              },
        dataType: "script"
      })
      return false;
    });
  });
</script>

The request_new_item controller is like this:

def request_new_item
  @return_item = ReturnItem.new 
end

and here is request_new_item.js.erb :

 $("#itemlist").append('<%= j render :partial => "return_items/return_items", :locals => {:f => f, :return_item => item } %>');

When I press the button addItem, I expect to generate a new partial, but actually, this doesn’t work. The console provide an error:

 ActionView::Template::Error (undefined local variable or method `f' for #<#<Class:0x007f5a302232b0>:0x007f5a380afea8>)

UPDATE:
I forgot to post the model:
return_request.rb:

class ReturnRequest < ActiveRecord::Base
    has_many :return_items, :class_name=>'ReturnItem', :foreign_key=>'RMA_Nmb', :primary_key=>'RMA_Nmb'
    accepts_nested_attributes_for :return_items
end

return_item.rb:

class ReturnItem < ActiveRecord::Base
  belongs_to :return_request, :class_name=>"ReturnRequest"
end

So, could anybody explain me how this happen, and how can I fix this? 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-06-13T10:24:44+00:00Added an answer on June 13, 2026 at 10:24 am

    In index.html.erb, the variable f is passed into the block, but in request_new_item.js.erb, where can f come? It is really undefined in that erb.

    I think the browser doesn’t have to request that piece of HTML from server. Instead, it can just duplicate the existing partial and append it. To make it easy to duplicate, you can wrap the partial in _return_item.html.erb with a DIV. You may need to adjust some names of fields in the partial before appending it.

    The gem called “nested_form” could be a choice too.

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

Sidebar

Related Questions

In my view, I have a form I want to dynamically render. This form
I have a constructor question for C#. I have this class: public partial class
I have this question, just in theory. I do some query results and there
I have this question in which I have a SQL Server Compact Edition database
I have this question because I am not familiar latest generation of MS VS
I have this question: How could I call a codebehind method from jquery? I
I have this question relating to Lucene. I have a form and I get
I have this question, i am just throwing it out there. I am implementing
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
hello i have this question i was trying to find a way to call

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.