awesome_nested_set adding a new category

in this example what if i didn't have a values for science, physics and gravity but had to get it from form what field would i use? my guess any of the 3 variables can be substituted with params[:id] ?

Create a root node:

science = Category.create!(:name => 'Science')

Put a new thing inside this root node:

physics = Category.create!(:name => 'Physics')

Put another thing inside the “physics” node:

gravity = Category.create!(:name => 'Gravity')

Again, unfortunately, I have little idea of exactly what you are
asking. If the form is generated by
form_for @category
then 'name' would be one of the fields expected to be in the form, so
you should be able to do
though it would be more usual to use new and save and then check the
return value of save in case there were validation errors.


Why not Category.create!(category_params)
instead of Category.create!(params[:category])
? thanks

isn’t params[:category] a reference to a single field and not all the params from the form

params[:category] is identical to category_params. As an old hand I
don't necessarily make use of later useful syntactical goodies in
rails. Look at the params structure in the controller and you will
see how the hash is organised. In fact I am not sure whether I like
using category_params as it is not obvious exactly what is being
referred to, whereas params[:category] can only refer to the category
hash within the params hash.