Forum: Ruby on Rails inline formsets?

02febcc7d5b8bd06cd813d3d3d4500aa?d=identicon&s=25 Cesar Devera (Guest)
on 2011-01-03 13:00
(Received via mailing list)
hi,

I'm new to Rails (I'm comming from Django) and I'm looking for
something equivalent to Django's Formsets (http://
docs.djangoproject.com/en/dev/topics/forms/formsets/) and Inline
Formsets (http://docs.djangoproject.com/en/dev/topics/forms/...
#using-an-inline-formset-in-a-view)

does Rails have anything like this?

for those who don't know Django, a formset is an html form that
represents several records at once, like this:

given an Article, a formset with 3 items would be like:

<form action="...">
<tr><th><label for="id_form-0-title">Title:</label></th><td><input
type="text" name="form-0-title" value="Django is now open source"
id="id_form-0-title" /></td></tr>
<tr><th><label for="id_form-0-pub_date">Pub date:</label></
th><td><input type="text" name="form-0-pub_date" value="2008-05-12"
id="id_form-0-pub_date" /></td></tr>
<tr><th><label for="id_form-1-title">Title:</label></th><td><input
type="text" name="form-1-title" id="id_form-1-title" /></td></tr>
<tr><th><label for="id_form-1-pub_date">Pub date:</label></
th><td><input type="text" name="form-1-pub_date" id="id_form-1-
pub_date" /></td></tr>
<tr><th><label for="id_form-2-title">Title:</label></th><td><input
type="text" name="form-2-title" id="id_form-2-title" /></td></tr>
<tr><th><label for="id_form-2-pub_date">Pub date:</label></
th><td><input type="text" name="form-2-pub_date" id="id_form-2-
pub_date" /></td></tr>
....
</form>

(please, ignore the clutter. just the INPUT tags matter)

and when the request is submitted, I just have to do this in my
controller to get it parsed:

ArticleFormSet = formset_factory(ArticleForm)
    if request.method == 'POST':
        formset = ArticleFormSet(request.POST)

(now, the formset object has a list of 3 Article objects)



thanks in advance,

Cesar
6228fc7c96122d25c088b7dee54db273?d=identicon&s=25 Andrey Koleshko (ka8725)
on 2014-03-13 22:47
Hello, Cesar.

I started to learn Django and I' Ruby developer. Unfortunately Rails
doesn't have something familiar out of the box. And you have to
implement this from scratch. I recommend to use form objects fro this
(again Rails doesn't provide them, so you have to implement them from
scratch by yourself). Check out this railscast to be introduced to the
subject: http://railscasts.com/episodes/416-form-objects

PS. Table in the view template should be written manually.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.