← Back to Upcase

Creating a page to edit many child objects with one submit--What JS Framework?


(Justin Gordon) #1

Any suggested best practice for creating a Rails UI to edit many child objects on one page?

A simple example would be putting in monthly stock returns for a portfolio of securities. The UI will allow editing the “return” values of stocks in the portfolio, and add another month’s worth of values easily. This would be tedious one record at a time.

There’s a related railscast on this topic: http://railscasts.com/episodes/165-edit-multiple-revised

I’ve seen suggestions not to use accepts_nested_attributes_for and to possibly use form objects for this sort of task.

I’m wondering if I’ll simple end up with a lot of coffeescript & jQuery to make come out nicely.

Or if it’s useful to try to work EmberJs into an existing Rails app.

While I’ve used AngularJs a bit, I’d rather focus on EmberJs, if I was going to learn one.

(And if you search “rails 4 emberjs”, my tutorial is first on Google!)

Thanks for suggestions.


(Bruce) #2

Have you checked out cocoon: https://github.com/nathanvda/cocoon? Sounds like what you might be looking for.


(Justin Gordon) #3

Looks promising. There’s a demo here: https://github.com/nathanvda/cocoon_simple_form_demo

I’ve seen some article references (such as http://matthewrobertson.org/blog/2012/09/20/decoupling-rails-forms-from-the-database/) to replacing “accepts_nested_attributes_for” with form objects. Wondering if anybody else has any opinions on accepts_nested_attributes_for.

I’m considering simply using accepts_nested_attributes_for without any fancy Javascript.

Here’s a sample from the cocoon demo.

class Project < ActiveRecord::Base
  has_many :tasks
  has_many :people
  belongs_to :owner, :class_name => 'Person'

  has_many :project_tags
  has_many :tags, :through => :project_tags, :class_name => 'Tag'

  accepts_nested_attributes_for :tasks, :reject_if => :all_blank, :allow_destroy => true
  accepts_nested_attributes_for :people, :reject_if => :all_blank, :allow_destroy => true
  accepts_nested_attributes_for :owner, :reject_if => :all_blank
  accepts_nested_attributes_for :tags
  accepts_nested_attributes_for :project_tags
end

(Derek Prior) #4

We have some notes on form objects and accepts_nested_attributes here: Form Objects


(Justin Gordon) #5

Totally getting hooked on React. Check out this interesting discussion about React in the context of EmberJS:

Anybody else using react on this forum?


(Cyle Hunter) #6

I dabbled with React a bit. It took a bit to get my head around some concepts like the difference between states and properties and JSX. What I enjoyed most about React was that it was easy to make ajaxy pages without having to go full blown backbone/ember/angular etc. while still being able to avoid the JQuery callback soup that is common with a lot of Rails applications.

You might also want to consider something like best_in_place, it’s probably the lowest hanging fruit when you want to make ajax-driven pages consisting of multiple resources.