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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:44:37+00:00 2026-05-13T05:44:37+00:00

I have a partial now looking like this: <%= render(:partial => ‘order’, :object =>

  • 0

I have a partial now looking like this:

<%= render(:partial => 'order', :object => Order.new %>

How can I build a few empty LineItem object into the Order.new as in :object => Order.new?

Note that Order has_many :line_items. and LineItem belongs_to :order

And as a commenter mentioned, this might at first seem to violate the MVC design, but I forgot to mention that this render is really in a link_to_function helper which serves to dynamically insert more fields of the attribute line item.

The actual helper looks like this:

#orders_helper.rb
  def add_line_item_link(name, form_scope)
    link_to_function name, :class => "add_line_item_link" do |page|
      line_item_html = render(:partial => 'line_item', :object => @order.line_items.new, :locals => {:f => form_scope})
      page << %{
        var time_index = new Date().getTime();
        var line_item_html = #{line_item_html.to_json};
        line_item_html = line_item_html.replace(/_\\d+/g, "_"+time_index);
        line_item_html = line_item_html.replace(/\\[\\d+\\]/g, "\\["+time_index+"\\]");
        $('line_items').insert({bottom: line_item_html});
      }
    end
  end

@order.line_items.new is what I like to work on:

first: I want instead of just one line_item to be built in the @order object, I want three.
second: the line item has an attribute named ‘title’, and whenever we get an order, pretty much every time the order has exactly three line items, one has title editor, one has title photographer, and one has title video-editor.

So I thought, maybe I can so something like:

#orders_controller.rb
@titles = %w(editor photographer video-editor)

#orders_helper.rb
...#same as above
:partial => 'line_items', :collection => lambda { @titles.each {|t| @order.line_items.build(:title => t) } return @order.line_items}
...

any suggestions?
Thank You

  • 1 1 Answer
  • 1 View
  • 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-13T05:44:38+00:00Added an answer on May 13, 2026 at 5:44 am

    In response to your changed question–

    #order.rb
    def default_line_items
      self.line_items.build(:title => "editor")
      self.line_items.build(:title => "photographer")
      self.line_items.build(:title => "video_editor")
      return self.line_items
    end
    #call to partial
    render (:partial => "line_item", :collection => order.default_line_items)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have a navigation partial that looks like this (x10 buttons)... <%
I have a (partial) qmake project file like this: TEMPLATE=lib TARGET=whatever SOURCES=whatever.cpp HEADERS=whatever.h This
I have this partial code: if ($getRecords = $con->prepare(SELECT * FROM AUCTIONS WHERE ARTICLE_NO
In my application (WPF) i have this window: public partial class Window1 : Window
I have my login-partial in my application.html.erb-layout. Now I want to validate it, if
So right now I have a partial view that just has a list of
I have a comment controller that uses a form partial to add comments. Now
I have some partial actions that I render with the Asp.Net Futures RenderAction method.
I've been looking at this Stackoverflow question and have the answer implemented. It works
Anyone knows if is possible to have partial class definition on C++ ? Something

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.