Giter Site home page Giter Site logo

ancestry's People

Contributors

cheerfulstoic avatar dburrows avatar fryguy avatar kueda avatar muitocomplicado avatar stefankroes avatar tjchambers avatar tomtaylor avatar vanderhoorn avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ancestry's Issues

parent_id in a form returns "undefined method"

I am not sure if this is related to the port and the modifications, but I noticed that when I am trying to do a simple "hook-up" of a model, it won't work.

This is my class:

class Node < ActiveRecord::Base
  has_ancestry orphan_strategy: :adopt, cache_depth: true

This is my schema for my Node.rb table:

# == Schema Information
#
# Table name: nodes
#
#  id             :integer          not null, primary key
#  family_tree_id :integer
#  created_at     :datetime
#  updated_at     :datetime
#  name           :string(255)
#  ancestry       :string(255)
#  ancestry_depth :integer          default(0)
#  max_tree_depth :integer          default(0)

This is my controller create & new actions:

  def new
    @node = Node.new(parent_id: params[:parent_id])
    respond_with(@node)
  end

  def create
    @family_tree = current_user.family_tree
    @node = @family_tree.nodes.new(node_params)
    @node.save
    respond_with(@node)
  end

My _form.html.erb (which is a simple_form, for what it's worth):

<%= f.input :parent_id, as: :hidden %>

This is the error I am getting:

undefined method `parent_id' for #<Node:0x007fac361ba1e0>

Any ideas?

Edit 1

For what it's worth, I swapped out the gems in my Gemfile and it works - as is - with the stock gem.

Here are the server logs for the working version:

Started GET "/nodes/new?parent_id=15" for 127.0.0.1 at 2015-01-17 19:07:04 -0500
Processing by NodesController#new as HTML
  Parameters: {"parent_id"=>"15"}
  Node Load (1.4ms)  SELECT  "nodes".* FROM "nodes"  WHERE "nodes"."id" = $1 LIMIT 1  [["id", 15]]
  FamilyTree Load (2.0ms)  SELECT "family_trees".* FROM "family_trees"
  Rendered nodes/_form.html.erb (19.3ms)
  Rendered nodes/new.html.erb within layouts/application (20.6ms)
  User Load (1.8ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
Completed 200 OK in 337ms (Views: 328.7ms | ActiveRecord: 5.1ms)


Started POST "/nodes" for 127.0.0.1 at 2015-01-17 19:07:14 -0500
Processing by NodesController#create as HTML
  Parameters: {"utf8"=>"โœ“", "authenticity_token"=>"F1HGLwIjDG3VaIYlnsu7NbROEiWBO8xqJtjh5MreI9E=", "node"=>{"parent_id"=>"15", "name"=>"Jerry", "family_tree_id"=>"2"}, "commit"=>"Create Node"}
  User Load (2.0ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
  FamilyTree Load (1.3ms)  SELECT  "family_trees".* FROM "family_trees"  WHERE "family_trees"."user_id" = $1 LIMIT 1  [["user_id", 1]]
  Node Load (4.7ms)  SELECT  "nodes".* FROM "nodes"  WHERE "nodes"."id" = $1 LIMIT 1  [["id", 15]]
   (9.4ms)  BEGIN
  SQL (5.1ms)  INSERT INTO "nodes" ("ancestry", "ancestry_depth", "created_at", "family_tree_id", "name", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"  [["ancestry", "15"], ["ancestry_depth", 1], ["created_at", "2015-01-18 00:07:14.201648"], ["family_tree_id", 2], ["name", "Jerry"], ["updated_at", "2015-01-18 00:07:14.201648"]]
   (1.4ms)  COMMIT
Redirected to http://localhost:3000/nodes/16
Completed 302 Found in 57ms (ActiveRecord: 24.0ms)


Started GET "/nodes/16" for 127.0.0.1 at 2015-01-17 19:07:14 -0500
Processing by NodesController#show as HTML
  Parameters: {"id"=>"16"}
  Node Load (4.2ms)  SELECT  "nodes".* FROM "nodes"  WHERE "nodes"."id" = $1 LIMIT 1  [["id", 16]]
  FamilyTree Load (2.6ms)  SELECT  "family_trees".* FROM "family_trees"  WHERE "family_trees"."id" = $1 LIMIT 1  [["id", 2]]
  User Load (5.0ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = $1 LIMIT 1  [["id", 1]]
  Rendered nodes/show.html.erb within layouts/application (13.3ms)
  User Load (3.2ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
Completed 200 OK in 274ms (Views: 256.1ms | ActiveRecord: 15.0ms)

This is the server log for the failed one:

Started GET "/nodes/new?parent_id=13" for 127.0.0.1 at 2015-01-17 18:45:27 -0500
  ActiveRecord::SchemaMigration Load (2.2ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by NodesController#new as HTML
  Parameters: {"parent_id"=>"13"}
  Node Load (1.4ms)  SELECT  "nodes".* FROM "nodes"  WHERE "nodes"."id" = $1 LIMIT 1  [["id", 13]]
  Rendered nodes/_form.html.erb (64.1ms)
  Rendered nodes/new.html.erb within layouts/application (70.1ms)
Completed 500 Internal Server Error in 122ms

NoMethodError - undefined method `parent_id' for #<Node:0x007fac361ba1e0>:

What is the setter for parents?

@tjchambers How do I actually set the parents of an object?

In my _form.html.erb for my Node object, I have the following:

<div class="field">
  <%= f.input :parents, collection: @node.family_tree.nodes - @node.parents, label_method: :name, value_method: :id, label: "Parent 1" %>
</div>

In my Node.rb model, I have this:

attr_accessible :name, :family_tree_id, :user_id, :description, :parent_id, :parent, :parents

In my NodesController.rb I have this:

private
def node_params
  params.require(:node).permit(:user_id, :family_tree_id, :name, :description, :parent_id, :parent, :parents)
end

But when I try to assign a parent to a Node, I get the following error:
unknown attribute: parents

I suspect it is because there is no parents setter.

How do you set them without it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.