天道酬勤,学无止境

Node expected, got String

I am trying to build a tree structure, so I created a Node model with a self-joining association:

class Node < ActiveRecord::Base
  has_many :child_nodes, :class_name => "Node", :foreign_key => "parent_id"
  belongs_to :parent, :class_name => "Node"

Here's the schema:

create_table "nodes", :force => true do |t|
  t.integer  "key"
  t.decimal  "value",      :precision => 8, :scale => 2
  t.decimal  "prob",       :precision => 8, :scale => 2
  t.integer  "parent_id"
  t.datetime "created_at"
  t.datetime "updated_at"
end

Everything seems to be working fine when I run tests or when I create a Node via the console. However, when I run the app and create a new Node via the form on /nodes/new, I get the following error:

ActiveRecord::AssociationTypeMismatch in NodesController#create

Node(#2162787060) expected, got String(#2151988680)

What seems to be the problem?

EDIT: Added form and create

<%= form_for(@node) do |f| %>
  <% if @node.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@node.errors.count, "error") %> prohibited this node from being saved:</h2>

      <ul>
      <% @node.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :key %><br />
    <%= f.number_field :key %>
  </div>
  <div class="field">
    <%= f.label :parent %><br />
    <%= f.number_field :parent %>
  </div>
  <div class="field">
    <%= f.label :value %><br />
    <%= f.number_field :value %>
  </div>
  <div class="field">
    <%= f.label :prob %><br />
    <%= f.number_field :prob %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Create:

def create
  @node = Node.new(params[:node])

  respond_to do |format|
    if @node.save
      format.html { redirect_to(@node, :notice => 'Node was successfully created.') }
      format.xml  { render :xml => @node, :status => :created, :location => @node }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @node.errors, :status => :unprocessable_entity }
    end
  end
end
标签

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Uncaught Error: Invariant Violation: Element type is invalid: expected a string
    i am trying to debug my react code. in my render method I try to put debugger and debugger. after I step over retun method its going to warning.js. after I step over warning.js if conditions its going to instantiateReactComponent.js I am not sure why its going to different files. can you tell me why its going to different files. not sure how to debug. it would be great if you guys give me some explaination so that in future I can fix the error my self providing the snippet of the code where it goes in step over function call each time error invariant.js?f23e:39 Uncaught Error: Invariant
  • 未捕获的错误:不变违规:元素类型无效:应为字符串(Uncaught Error: Invariant Violation: Element type is invalid: expected a string)
    问题 我正在尝试调试我的反应代码。 在我的渲染方法中,我尝试放置调试器和调试器。 在我跳过 retun 方法后,它会转到 warning.js。 在我跳过warning.js 之后,如果条件它会实例化ReactComponent.js 我不确定为什么它会转到不同的文件。 你能告诉我为什么它会转到不同的文件。 不知道如何调试。 如果你们给我一些解释,以便将来我可以自己修复错误,那就太好了提供代码片段,它每次都在函数调用中逐步执行 error invariant.js?f23e:39 Uncaught Error: Invariant Violation: Element type is invalid: 期望字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义。 检查sports-container的渲染方法。 渲染(){ const {sportsType,sportsDevice,sportsWordings,id } = this.props; 让sportsEvent = true; debugger; if (sportsEvent === true) { return ( 警告.js /** * 与 invariant 类似,但仅在不满足条件时记录警告。 * 这可用于在关键路径中记录开发环境中的问题。 删除生产环境的日志代码将保持*相同的逻辑并遵循相同的代码路径
  • 模块版本不匹配。 预期为11,得到1(Module version mismatch. Expected 11, got 1)
    问题 Platform: Linux 当运行我的node.js程序时,出现以下错误 Error: Module version mismatch. Expected 11, got 1. 回答1 您可能会给出这样的错误: Error: Module version mismatch. Expected 11, got 1. at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (/home/user/node_modules/xml2json/node_modules/node-expat/lib/node-expat.js:4:13) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require
  • Tensorflow Object Detection API Invalid argument: Shape mismatch in tuple component 16. Expected [1,?,?,3], got [1,182,322,4]
    This is a follow-up question from this Github issue. To cut a long story short, I tried to use the Tensorflow Object detection API with my own dataset. Everything was working just fine until all of a sudden it crashed with the following error messages : ... INFO:tensorflow:global step 10635: loss = 0.3392 (0.822 sec/step) INFO:tensorflow:global step 10636: loss = 0.3529 (0.823 sec/step) INFO:tensorflow:global step 10637: loss = 0.3305 (0.831 sec/step) 2017-09-14 20:02:02.545415: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid
  • Jest fails with “Unexpected token *” on import statement
    Why does Jest fail with "Unexpected token *" on a simple import statement... Error log: Admin@Admin-PC MINGW32 /d/project (master) $ npm run test > MyApp@0.0.1 test D:\project > jest FAIL __tests__/App-test.tsx ? Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript. By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules". Here's what you can do: • To have some of your "node_modules" files transformed, you can specify a
  • TensorFlow random_shuffle_queue已关闭且元素不足(TensorFlow random_shuffle_queue is closed and has insufficient elements)
    问题 我正在通过从tfrecords获取想法来读取一批图像(由此转换) 我的图像是cifar图像[32、32、3],正如您在读取和传递图像时所看到的,形状是正常的( batch_size=100 ) 据我所知,日志中指出的2个最值得注意的问题是 12228的形状,我不知道从哪里得到的。 我所有的张量都为[32,32,3]或[None,3072]形状样品用完 Compute status: Out of range: RandomSuffleQueue '_2_input/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0) 我该如何解决? 日志: 1- image shape is TensorShape([Dimension(3072)]) 1.1- images batch shape is TensorShape([Dimension(100), Dimension(3072)]) 2- images shape is TensorShape([Dimension(100), Dimension(3072)]) W tensorflow/core/kernels/queue_ops.cc:79] Invalid
  • 模块版本不匹配。 预期 49,得到 48(Module version mismatch. Expected 49, got 48)
    问题 我正在使用 Electron 模块 mdns,但出现此错误 A JavaScript error occurred in the main process Uncaught Exception: Error: Module version mismatch. Expected 49, got 48. at Error (native) at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:167:20) at Object.Module._extensions..node (module.js:568:18) at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:167:20) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home
  • React.createElement: type is invalid — expected a string, but got: object
    I've just upgraded to Webpack 2.2 today and have been reading through their guides, which are still a work in progress it seems. I am having difficulties setting up my application to use webpack-dev-server with hot module reloading. The guide I was following via the webpack documentation is here, but I am having to modify it to work with a development/production application. https://webpack.js.org/guides/hmr-react/ The two errors I get are the following... Uncaught Error: _registerComponent(...): Target container is not a DOM element. at invariant (eval at <anonymous> (index.js:2), <anonymous>
  • Packets out of order. Got: 80 Expected: 0 node.js
    Here is my (very simple) code : var connection = mysql.createConnection(infosDB); connection.connect() connection.query(`SELECT * FROM action`, function(err, data){ console.log(data); }) The action table is not empty... I think my database is ok. This code works very well for me on localhost. However, I bought A2 Hosting to launch node.js (v6.10.3 on localhost and server) project and I get that error when I try to launch this simple code. { Error: Packets out of order. Got: 80 Expected: 0 at Parser.write (/home/hello1234/public_html/myapp/node_modules/mysql/lib/protocol/Parser.js:42:19) at
  • TensorFlow random_shuffle_queue is closed and has insufficient elements
    I'm reading batch of images by getting idea here from tfrecords(converted by this) My images are cifar images, [32, 32, 3] and as you can see while reading and passing images the shapes are normal (batch_size=100) the 2 most notable problems stated in the log, as far as I know is Shape of 12228, which I don't know from where I get this. All my tensors are either in shape [32, 32, 3] or [None, 3072] Running out of sample Compute status: Out of range: RandomSuffleQueue '_2_input/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0) How can I
  • Node + Express .post 路由抛出错误。 预期回调,得到对象(Node + Express .post route throwing error. Expected callback, got object)
    问题 我目前正在使用 Express + Node 开发一个应用程序。 我最近使用以下语法向app.js文件添加了一个新的.post路由: app.post('/api/posts/saveComment', posts.saveComment); posts在上面定义为: var posts = require('./routes/posts.js'); saveComment定义如下: exports.saveComment = function(req, res) { //function stuff in here, yada yada } 现在,当我尝试运行应用程序时,节点抛出错误: Error: .post() requires a callback functions but got a [object Undefined] saveComment显然是一个函数,我不明白为什么它看不到这个。 我在saveComment正上saveComment了另一个函数,我可以saveComment地引用它,但是将该函数内容复制到saveComment内容仍然会产生相同的错误。 我不知所措,非常感谢任何帮助。 每个请求, posts.js内容 var mongo = require('../mongo.js'); exports.queryAll = function(req
  • “错误:在 C++ 中需要一个类型,得到 'classname'”(“error: Expected a type, got 'classname'” in C++)
    问题 使用以下代码: template <typename T> class node { [. . .] }; class b_graph { friend istream& operator>> (istream& in, b_graph& ingraph); friend ostream& operator<< (ostream& out, b_graph& outgraph); public: [...] private: vector<node> vertices; //This line 我越来越: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’ error: expected a type, got 'node' error: template argument 2 is invalid 在指示的行上。 在使用它的 b_graph 之前明确定义了节点 - 我在这里做了什么? 回答1 node不是一个类,它是一个类模板。 您需要实例化它以将其用作vector的元素类型,例如, vector<node<int> > vertices; (以int为例
  • Error TS1005: ';' expected. TypeScript Angular 6 For First Build error rxjs inside node_modules
    I'm building my first Angular Application. I'm creating a new Angular application using this command ng new purchase-section. But when I executing the application using ng serve -o I got the following error. ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected. I have inspected types.d.ts as I know it is created by Angular. I'm not able to understand the error. Note that after I got this error I deleted node
  • Node + Express .post route throwing error. Expected callback, got object
    I'm currently working on an app using Express + Node. I recently added a new .post route to the app.js file, using the following syntax: app.post('/api/posts/saveComment', posts.saveComment); posts is defined above as: var posts = require('./routes/posts.js'); And saveComment is defined as so: exports.saveComment = function(req, res) { //function stuff in here, yada yada } Now, node is throwing an error when I try to run the app: Error: .post() requires a callback functions but got a [object Undefined] saveComment is clearly a function, I'm not understanding why it can't see this. I have
  • Module version mismatch. Expected 49, got 48
    I am using Electron module mdns and I am getting this error A JavaScript error occurred in the main process Uncaught Exception: Error: Module version mismatch. Expected 49, got 48. at Error (native) at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:167:20) at Object.Module._extensions..node (module.js:568:18) at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:167:20) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at
  • “error: Expected a type, got 'classname'” in C++
    Using the following code: template <typename T> class node { [. . .] }; class b_graph { friend istream& operator>> (istream& in, b_graph& ingraph); friend ostream& operator<< (ostream& out, b_graph& outgraph); public: [...] private: vector<node> vertices; //This line I'm getting: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’ error: expected a type, got 'node' error: template argument 2 is invalid On the indicated line. Node is clearly defined before b_graph which uses it - what have I done here?
  • Can't run node from web server
    I was trying to run npm from a PHP web page, but it would never run. I always got an exit code of 127 and no output. After doing some testing I narrowed down the problem to the shebang in npm which looks like this: #!/usr/bin/env node Pretty standard, but I did up some test code: <?php $result = exec("/usr/bin/env node --version", $output, $exit); var_dump($result); var_dump($exit); $result = exec("node --version", $output, $exit); var_dump($result); var_dump($exit); $result = exec("/usr/bin/env gzip --version", $output, $exit); var_dump($result); var_dump($exit); And got this output in my
  • eXist-db passing parameters to templates through controller.xql (URL mapping)
    I am working with eXist-db 4.2.1 and Xquery 3.1 using the eXist's default installation of controller.xql and view.xq. I have a document.html to which I pass any incoming url structured with /doc/some-requested-doc-id at the end to produce a dynamically-created page based on some-requested-doc-id. So, the incoming url can be either http://localhost:8080/exist/apps/deheresi/doc/MS609-0001 or http://localhost:8080/exist/apps/deheresi/doc/MS609-0001.xml and they are treated the same... In the file controller.xql I have a condition for matching this request, which identifies /doc/ and cleans up the
  • 在Python的单元测试中比较XML(Comparing XML in a unit test in Python)
    问题 我有一个对象,可以从XML字符串构建自己,然后将其写出到XML字符串。 我想编写一个单元测试来测试通过XML的往返,但是在比较这两个XML版本时遇到了麻烦。 空格和属性顺序似乎是问题所在。 有关如何执行此操作的任何建议? 这是在Python中进行的,而我正在使用ElementTree(在这里,这并不是很重要,因为我只是在此级别上处理字符串中的XML)。 回答1 首先规范2个XML,然后可以对其进行比较。 我已经在lxml中使用了以下内容 obj1 = objectify.fromstring(expect) expect = etree.tostring(obj1) obj2 = objectify.fromstring(xml) result = etree.tostring(obj2) self.assertEquals(expect, result) 回答2 这是一个古老的问题,但是由于属性顺序的原因,被接受的Kozyarchuk的答案对我不起作用,并且最小解决方案也不起作用(不知道为什么,我还没有调试它)。 这是我最终想出的: from doctest import Example from lxml.doctestcompare import LXMLOutputChecker class XmlTest(TestCase): def assertXmlEqual
  • How to select a particular Node name and its values in XML using Oracle SQL query?
    I have a table called SOAP_MONITORING in which i have RESPONSE_XML column which is CLOB datatype. In this column large xml string is stored. I want to get the node name and node value from this xml string. Here is my xml : <?xml version='1.0' encoding='utf-8'?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:placeShopOrderResponse xmlns:ns="http://service.soap.CDRator.com"> <ns:return xmlns:ax2133="http://signup.data.soap.CDRator.com/xsd" xmlns:ax2134="http://core.signup.data.soap.CDRator.com/xsd" xmlns:ax2127="http://data.soap.CDRator.com/xsd"