Forum: Ruby on Rails Nested set - problems when creating child item

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.
3264e5664540abc9002b3a1f6f6f9f21?d=identicon&s=25 cassiozen (Guest)
on 2009-02-20 16:18
(Received via mailing list)
Hi,

I've created a Model with Better Nested Set, but i'm having problems
to create child items

My workflow is:
 - In the (new) form, i pass the desired parent_id in a hidden field.
 - In the create action, i create the register and after saving it i
use the move_to_child_of method.

Everything works!  My only problem is that Rails warns that I can't
mass asign the property "parent_id"

How can i avoid this warning? Below is my create action:

def create
    @invite = Invite.new(params[:invite])
    begin
      @parent_invitee = Invite.find_by_id(params[:invite][:parent_id])
    rescue Exception => exc
        logger.error("Invalid parent_id: #{exc.message}")
        render :action => "new"
    end
    respond_to do |format|
      if @invite.save
        @invite.move_to_child_of(@parent_invitee.id)
        flash[:notice] = 'Invite was successfully created.'
        format.html { redirect_to :action => "show" }
       ...
This topic is locked and can not be replied to.