English 中文(简体)
set套——如何放置物品?
原标题:Awesome nested set - how to put there items?

我的表格结构如下:

| id         | int(11)  | NO   | PRI | NULL    | auto_increment |
| user_id    | int(11)  | YES  |     | NULL    |                |
| parent_id  | int(11)  | YES  |     | NULL    |                |
| lft        | int(11)  | YES  |     | NULL    |                |
| rgt        | int(11)  | YES  |     | NULL    |                |
| created_at | datetime | YES  |     | NULL    |                |
| updated_at | datetime | YES  |     | NULL    |                |
+------------+----------+------+-----+---------+----------------+

In the form where I create a new items to the tree structure I have in a hidden input always the parent of item, that I just create.

在一名控制人员中,我这样做:

def create
    @user = User.new(params[:user])

    respond_to do |format|
      if @user.save
        save_tree = TreeStruct.create!(:user_id => @user.id)
        save_tree.move_to_child_of(params[:parent])

        format.html { redirect_to(root_url, :notice =>  OK. ) }
        format.xml  { render :xml => @user, :status => :created, :location => @user }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
      end
    end
  end

但是,我总是在试图制造这一树子并生产树子的时候,我会发现错误:

Couldn t find TreeStruct with id=28

The number 28 is the ID od parent item. The currently created item saved to database, bud the column parent_id has the value NULL.

I am a bit confusing of it - what I am doing wrong? Why I am getting this error? And how I should create a root of the tree and then add other items?

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签