Forum: Ruby on Rails RESTful acts_as_tree

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E7349346374a0c685bf8055b7977af5c?d=identicon&s=25 Andrei Erdoss (cautaro)
on 2008-11-13 12:36
(Received via mailing list)
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
This topic is locked and can not be replied to.