Hello,
I was trying to use the acts_as_tree plugin and I got stuck when
trying to do it in a RESTful way. I have a Place model that can have
and belong to other places. What is the correct method of creating new
places in a RESTful way? I don’t necessarily care about have an url /
place/id/place/id. I’m mostly interested to know the correct way of
passing the parent_id in order to create the new place.
This is my create method:
POST /places
def create
@parent_place = Place.find(params[:place_id])
or do I use @parent_place = Place.find(params[:parent_id])
@place = @parent_place.children.build(params[:place])
respond_to do |format|
if @place.save
flash[:notice] = 'Place was successfully created.'
format.html { redirect_to(@place) }
else
format.html { render :action => "new" }
end
end
end
routes.rb
map.resources :places, :has_many => :places # is this legal?
Some guidance would be really appreciated. Thanks