# In\_place\_collection\_editor

**URL:** <https://www.ruby-forum.com/t/in-place-collection-editor/87134>\
**Category:** Rails\
**Created:** [March 25, 2006, 6:31pm UTC](https://www.ruby-forum.com/t/in-place-collection-editor/87134 "2006-03-25T18:31:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruairi\_Mc\_Comb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@Ruairi\_Mc\_Comb](https://www.ruby-forum.com/u/Ruairi_Mc_Comb)\
**Post date:** [March 25, 2006, 6:31pm UTC](https://www.ruby-forum.com/t/in-place-collection-editor/87134/1 "2006-03-25T18:31:12Z")

</div>

Hi,

I’m trying to write a helper for Scriptaculous’ InPlaceCollectionEditor  
component. I’ve already submitted a patch  
([http://dev.rubyonrails.org/ticket/4302](http://dev.rubyonrails.org/ticket/4302)). This was a drunk patch; it  
needs a bit of work (Don’t drink & code!). So far I’ve gotten it to work  
correctly with normal collections, but I want to use it for belongs\_to  
relations as well.

I want to build a test case for the in\_place\_collection\_editor field for  
which I need to know how to do the following (in rails core trunk):

How do I simulate a controller?  
How do I simulate an instance variable on that controller?  
How do I simulate an Array of ActiveRecord instances? Can this array be  
loaded from fixtures?

I basically want to do the following:

The model:

class Post \< ActiveRecord::Base  
belongs\_to :section  
end

class Section \< ActiveRecord::Base  
has\_many :posts  
end

There would be a “post” instance variable set on the controller.

I’ve tried setting this up as I’ve seen in other tests (using structs)  
as such:

def setup  
@sections = [  
Section.new(:id =\> 1, :name =\> ‘News’),  
Section.new(:id =\> 2, :name =\> ‘Gossip’),  
Section.new(:id =\> 3, :name =\> ‘Slander’)  
]  
@post = Post.new(:id =\> ‘1’, :title =\> ‘Foo’, :section =\>  
@sections[0])

@controller = Class.new do  
def url\_for(options, \*parameters\_for\_method\_reference)  
url = “[http://www.example.com/](http://www.example.com/)”  
url \<\< options[:action].to\_s if options and options[:action]  
url  
end  
end  
@controller = @controller.new  
end

But I’m not able to use this setup as ActionView::Helpers::InstanceTag  
uses a method of CGI to get to the instance variable set on the  
controller:

def object  
@object || @template\_object.instance\_variable\_get(“@#{@object\_name}”)  
end

Also the structs don’t seem to behave as I expected them to (they don’t  
seem to respond to .send, nor am I able to access properties), weird  
thing is that ActiveRecord objects do behave.

I’d like to be able to develop this using tests. When I’m developing  
this as a plugin it’s a PITA to have to restart the server for the  
changes to reload.

Anybody interested in the code (in plugin form) can check it out from:

[http://ruairimccomb.com/svn/in\_place\_collection\_editor/](http://ruairimccomb.com/svn/in_place_collection_editor/)
