meta_row question

3 views
Skip to first unread message

Johannes Fahrenkrug

unread,
May 14, 2009, 10:35:02 AM5/14/09
to Radiant CMS: Dev
Hi,

I'm using radiant edge from github and I'm following this tutorial:
http://wiki.github.com/radiant/radiant/creating-a-custom-page-type
I'm having trouble with the /vendor/extensions/tennis/app/views/admin/
pages/_player_base_info.html.haml

In the tutorial it reads:
- if @page.is_a?(PlayerPage)
%table.fieldset
- ['player_first_name', 'player_last_name', 'player_rank'].each do
|field|
= render :partial => "meta_row",:locals => {:f => self}, :object
=> {:field => field, :type => "text_field", :args => [{:class =>
'textbox', :maxlength => 100}]}


However, there are 2 problems. First of all, it must be
:args => [{}, {:class => 'textbox', :maxlength => 100}]
instead of just
:args => [{:class => 'textbox', :maxlength => 100}]
So that the html attributes get rendered correctly.

The 2nd problem is that :locals => {:f => self} doesn't seem to work.
The generated field name are
<input class="textbox" id="player_first_name_" maxlength="100"
name="player_first_name[]" size="100" type="text" />
instead of
<input class="textbox" id="page_player_first_name" maxlength="100"
name="page[player_first_name]" size="100" type="text" />

"self" is an instance of ActionView::Base which is not the current
form instance that we'd like to access in the partial.

So my question is: How do I access the current open form instance in a
partial that should add fields to the edit/new page?

- Johannes

--
http://springenwerk.com

Johannes Fahrenkrug

unread,
May 19, 2009, 9:00:24 AM5/19/09
to Radiant CMS: Dev
Anybody?

William Ross

unread,
May 19, 2009, 9:11:50 AM5/19/09
to radiant...@googlegroups.com


From a quick look through the meta_row code it looks like an old and
possibly now neglected attempt to dry up the interface. For most
purposes you could probably ignore it and just use form helpers as
usual. In that case the idiom you want is probably either this:

- form_for :player, {...} do |f|
= render :partial => "form", :object => f

or something like

- form_for :player, {...} do |f|
= render :partial => "player_fields", :locals => {:form => f}

either of which would allow you to call FormHelper methods in the
partial with eg

= form.text_field :first_name

If you want to persevere with the meta_row mechanism, the best
approach is probably to have a look at what happens inside admin/
pages_controller (this is in the radiant files, not in your app) for
the definition of rows andapp/views/admin/pages/_meta_row.html.haml
for the way the rows are then displayed in the page-editing view.
There may have been changes since that wiki page was written.

best,

will


Johannes Fahrenkrug

unread,
May 19, 2009, 9:20:08 AM5/19/09
to Radiant CMS: Dev
Hi Will,

Thanks for your reply.
I don't want to open a new form with "form_for" though. That tutorial
added fields to the pages table. So I want to add fields to the
already-open form_for :page. That's what the tutorial does, but I
couldn't find out how to access the variable that holds the "form"
object for the already-open page form. "self", as mentioned in the
tutorial, doesn't make sense and doesn't seem to work, either.

- Johannes

William Ross

unread,
May 19, 2009, 9:41:42 AM5/19/09
to radiant...@googlegroups.com
On 19 May 2009, at 14:20, Johannes Fahrenkrug wrote:

> Hi Will,
>
> Thanks for your reply.
> I don't want to open a new form with "form_for" though. That tutorial
> added fields to the pages table. So I want to add fields to the
> already-open form_for :page. That's what the tutorial does, but I
> couldn't find out how to access the variable that holds the "form"
> object for the already-open page form. "self", as mentioned in the
> tutorial, doesn't make sense and doesn't seem to work, either.


Oh, I see. Sorry. In that case you'll probably find the functionality
described under 'Add partial with fields to the page edit view' more
useful if you ignore the meta_row stuff. I don't really know why the
author of that page would choose to use the meta_row mechanism rather
than just calling for a text_field. Even if it worked it would put the
fields inside a <tr>.

>>>> The 2nd problem is that :locals => {:f => self} doesn't seem to
>>>> work.

You're quite right: for that to make sense f should be set to the
fieldset or the form, not the ActionView instance, and I have never
worked out how to get at those in in a newly added partial. I always
end up falling back on the old FormTagHelper syntax and using the
@variable.

Sorry not to be more useful,

will


CarbonJoeTunis

unread,
Jul 9, 2009, 2:17:01 PM7/9/09
to Radiant CMS: Dev
so any solution for this issue. i'm running into the exact same issue.
the custom fields are not part of the "page" hash, and therefore, are
not being included in my update (while doing an EDIT).

CarbonJoeTunis

unread,
Jul 10, 2009, 1:32:08 PM7/10/09
to Radiant CMS: Dev
i decided to switch to just using form helpers and that worked, like
this:

- if @page.is_a?(AwardPage)
- f = self
%table.fieldset
- ['company_name', 'product_name'].each do |field|
%tr
%th.label
= label(:page, field)
%td.field
= f.text_area "page", field
Reply all
Reply to author
Forward
0 new messages