如何从控制台运行控制器关注方法?(How can I run a controller concern method from the console?)
如果我有控制器问题,例如:
module MyConcern def concern_method param puts param.inspect end end
如何从控制台测试方法
concern_method
?使用此处描述的方法: 如何在Rails中从控制台调用控制器/视图方法? 我可以访问应用程序控制器:
controller = ActionController::Base::ApplicationController.new
...但是这会引发错误:
controller.concern_method "hello world" NoMethodError: undefined method `concern_method` for #<ApplicationController:0x000001091fbad0>
当从控制台实例化时,问题是否未自动添加到控制器?
If I have a controller concern, for example:
module MyConcern def concern_method param puts param.inspect end end
How can I test the method
concern_method
from the console?Using methods described here: How do I call controller/view methods from the console in Rails? I can access the application controller using:
controller = ActionController::Base::ApplicationController.new
... but then this throws an error:
controller.concern_method "hello world" NoMethodError: undefined method `concern_method` for #<ApplicationController:0x000001091fbad0>
Is the concern not added automatically to the controller when it is instantiated from the console?
原文:https://stackoverflow.com/questions/25812420
最满意答案
您正在使用networkx的2.0版本。 从使用
G.degree()
的词典变为使用类似字典(但不是dict)的DegreeView
。 请参阅本指南 。要获得列表中的学位,您可以使用列表理解 :
degrees = [val for (node, val) in G.degree()]
You are using version 2.0 of networkx. Which changed from using a
dict
forG.degree()
to using a dict-like (but not dict)DegreeView
. See this guide.To have the degrees in a list you can use a list-comprehension:
degrees = [val for (node, val) in G.degree()]
相关问答
更多-
从文档 : 节点颜色。 可以是单个颜色格式的字符串,也可以是与nodelist具有相同长度的一系列颜色。 如果指定了数值,则使用cmap和vmin,vmax参数将它们映射到颜色。 有关更多详细信息,请参阅matplotlib.scatter。 part = community.best_partition(G)为每个节点分配社区 - part是dict, part[node]是节点所属的社区(每个都分配了一个整数)。 后来的values = [part.get(node) for node in G.nod ...
-
以下作品: sorted(G.degree, key=lambda x: x[1], reverse=True) The following works: sorted(G.degree, key=lambda x: x[1], reverse=True)
-
如何在python中在networkx中绘制具有重复边缘的图形(How to draw a graph with duplicate edges in networkx in python)[2022-03-04]
我不是networkx专家,但根据这里的文档: Multigraphs NetworkX为图形提供类,允许任何一对节点之间有多条边。 MultiGraph和MultiDiGraph类允许您两次添加相同的边,可能使用不同的边数据。 这对于某些应用程序来说可能很强大,但是很多算法在这些图表上没有很好的定义。 最短路径就是一个例子。 如果结果明确定义,例如MultiGraph.degree(),我们提供该函数。 否则,您应该转换为标准图形,以使测量得到明确定义。 因此,如果进行了一项更改,该示例应该可以工作 - ... -
给定具有一组节点的图G ,最简单的事情就是 mapping = {old_label:new_label for new_label, old_label in enumerate(G.nodes())} H = nx.relabel_nodes(G, mapping) 这将创建一个字典mapping其键是旧标签,其值是新标签(在字典理解中读取)。 新标签的排序由G.nodes()返回值(您无法控制)的顺序给出。 新图H的节点标签已更改。 如果需要特定订单,则需要适当地对G.nodes()进行排序。 所以 ...
-
使用带有networkx库的Python在图形中创建复杂结构(Creating complex structures in graphs using Python with networkx library)[2020-02-10]
问题是你试图在三个元素之间生成一条边。 add_edges_from()函数获取元组列表并在每个元组的两个元素之间创建边。 例如 g = networkx.Graph() g.add_edges_from([(1,2), (3,4)]) 会产生两条边:一条在节点1和2之间,另一条在节点3和4之间。 zip函数在您的代码中通过集合user.user1和user.user2 ,返回这样的元组列表(确切地说,它是一个zip对象,但在这种情况下,它被视为与列表完全相同)。 在您的示例中,列表将如下所示: [('B ... -
原因是图表是无向的。 igraph和networkx处理I - J平局和J - I networkx对待。 panda.intersection只会处理完全匹配(即数据帧A中的第1列与数据帧B中的第1列匹配,数据帧A中的第2列与数据帧B中的第3列匹配)。 library(igraph); library(dplyr) set.seed(1034) g1 <- sample_gnp(20, 0.25, directed = F) set.seed(1646) g2 <- sample_gnp(20, 0.25 ...
-
你看到的问题是由 IPList = [[] for i in range (20)] 当len(pkts)小于20时,这导致parsePcap()返回一个带有空列表的序列列表或者末尾的列表: parseOutput = [ ('172.16.254.128', '216.58.208.206'), ... ('172.16.254.128', '216.58.208.227'), [], #<---------------- This is causing the problem ] 将parseO ...
-
该错误在绘图节点的功能中。 p.keys()值必须放在nodelist和node_color的列表中,否则它不起作用。 所以正确的是: nx.draw_networkx_nodes(G,pos,nodelist=list(p.keys()),node_size=80,node_color=list(p.values()), cmap=plt.cm.Reds_r) plt.axis('off') plt.show() The error is in the function for drawing node ...
-
NetworkX在有向图中找到特定节点的root_node(NetworkX find root_node for a particular node in a directed graph)[2022-01-09]
编辑2017年11月请注意,这是在networkx 2.0发布之前编写的。 有一个迁移指南,用于将1.x代码更新为2.0代码(特别是使其兼容) 这是一个简单的递归算法。 它假设最多只有一个父母。 如果某些东西没有父母,那就是根。 否则,它返回其父节点的根。 def find_root(G,node): if G.predecessors(node): #True if there is a predecessor, False otherwise root = find_root( ... -
通过Networkx在python中获取图形中每个节点的度数(Get degree of each nodes in a graph by Networkx in python)[2022-08-07]
您正在使用networkx的2.0版本。 从使用G.degree()的词典变为使用类似字典(但不是dict)的DegreeView 。 请参阅本指南 。 要获得列表中的学位,您可以使用列表理解 : degrees = [val for (node, val) in G.degree()] You are using version 2.0 of networkx. Which changed from using a dict for G.degree() to using a dict-like (bu ...