Skip to content

Instantly share code, notes, and snippets.

@jackdempsey
Created September 25, 2010 23:03
Show Gist options
  • Save jackdempsey/597396 to your computer and use it in GitHub Desktop.
Save jackdempsey/597396 to your computer and use it in GitHub Desktop.
Trying to figure out how to get a model that has submodels (of the same class) to be able to use IR to set things up.
model is:
class Item < ActiveRecord::Base
has_many :subitems, :class_name => "Item"
end
Right now it works well for normal Items. Now I'd like to setup a controller to handle adding subitems to an item. So far I haven't been able to do this. Not sure if I should use another IR controller, the same Item IR controller but with a special action for new/create to handle when we're adding a normal item vs a subitem to an item...or maybe just a separate controller that doesn't inherit from IR.
I've copied the controller in as I have it now--it seems @item is defined correctly but it's looking in inherited_resources/new for some reason instead of the correct items/ folder.
Is there a group, mailing list, IRC channel or some place to ask these things that's good? Just file an issue that's really a question?
Update:
I think this solution works well. Keep it in the same controller and use this:
def create
@item = parent.items.build(params[:item])
@item.item_id = params[:item_id] if params[:item_id]
create!
end
class SubitemsController < InheritedResources::Base
belongs_to :item
defaults :resource_class => Item, :instance_name => 'item'
def new
new! do |format|
#render :text => @item.inspect and return
respond_with(@item) and return
end
end
end
Template is missing
Missing template inherited_resources/new with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :haml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/Users/jack/projects/sample_app/app/views", "/Users/jack/projects/sample_app/vendor/plugins/dynamic_form/app/views", "/Users/jack/.rvm/gems/ruby-1.9.2-p0/gems/devise-1.1.2/app/views", "/Users/jack/.rvm/gems/ruby-1.9.2-p0/bundler/gems/subdomain-fu-c6fbf945cf3f/app/views"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment