2

I am using attribute_fu to render a nice block of rows for a particular table.

<%= f.render_associated_form(@foo.bars, :new => 5) %>

I would like to have the bar partial have some notion of a bit of state. (Because the notion is specific to the view, I do not want to externalize this to the Bar model itself and calculate it in the controller.) For simplicity's sake, pretend it is the index of the bar in the @foo.bars list.

(I am aware that if this was the case I could use the :collection => @foo.bars to enable bar_counter... this doesn't appear to function in my tests but I have seen docs for it.)

My question -- how do I pass a variable into the partial such that I can keep and edit the state? Naively, I assumed that doing something like

<% @tmp = {:index => 1} %>
%= f.render_associated_form(@foo.bars, :new => 5, :locals => {:tmp => @tmp}) %>

#goes in the view
<%= tmp[:index] += 1 %>

would work. tmp gets passed appropriately but calling [] throws "Uh oh, you just called a method on nil". Surprisingly to me, I can do tmp.inspect, tmp.class, etc to look at the Hash, and these have the results I would expect. But tmp[:index] or tmp[:anything_I_want] cause it to blow up.

Making tmp an array had similar results.

Any ideas?

4

2 回答 2

1

我最终以彻底的 Rails 方式解决了这个问题——修补 :attribute_fu 以满足我的需求。希望我能尽快向社区发布我的补丁。

于 2008-11-07T02:31:31.913 回答
0

The behavior you describe above seems like it must be a bug in attribute_fu, since the local isn't getting properly passed along, which it definitely should. I'd be interested to know what you did to patch it.

于 2008-11-10T16:57:20.950 回答