Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 面对“U到”链接的问题;编辑";在轨_Ruby On Rails_Ruby_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 面对“U到”链接的问题;编辑";在轨

Ruby on rails 面对“U到”链接的问题;编辑";在轨,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我正在尝试以带有编辑选项的表格格式显示所有指标。但是,我最终得到了以下错误 在索引视图中,我可以看到所有数据。但当我点击编辑链接时,它并没有重定向到编辑视图,在那个里我有不同的列要显示 索引视图: <%= form_for :metrics_controller, url: metrics_path(@metric), method: :get do |f| %> <table id="metrics"> <thead> <tr i

我正在尝试以带有编辑选项的表格格式显示所有指标。但是,我最终得到了以下错误

在索引视图中,我可以看到所有数据。但当我点击编辑链接时,它并没有重定向到编辑视图,在那个里我有不同的列要显示

索引视图:

<%= form_for :metrics_controller, url: metrics_path(@metric), method: :get do |f| %>
  <table id="metrics">
    <thead>
    <tr id="AllMetricColumnNames">
      <th id="CommentsColumn">Comments</th>
      <th id="EditColumn">Edit</th>
    </tr>
    </thead>
    <% @metricAll.each do |data| %>
      <tr id="AllMetricValues">
        <td id="Comments"><%= data.Comments %></td>
        <td id="EditButton"><%= link_to "Edit", edit_metric_path(@metricAll) %></td>
    <% end %>
    </tr>
  </table>
<% end %>
class MetricsController < ApplicationController
  def index
    @metricAll = Metric.all
  end

  def show
    @metric = Metric.find(params[:id])
  end

  def edit
    @metric = Metric.find(params[:id])
  end

  private def post_params
    params.require(:metric).permit(:Metric, :Comments)
  end
end
  root 'metrics#index'
  get 'index' => 'metrics#index'
  get 'edit' => 'metrics#edit'
  resources :metrics

您正在传递编辑路由的所有指标。离开

<td id="EditButton"><%= link_to "Edit", edit_metric_path(@metricAll) %></td>



数据
是代码中的当前度量

根据屏幕截图,错误在模型中。 另外,正如其他人所提到的,您应该删除那些
get
路由,因为
resources:metrics
将为您的所有CRUD操作a.ka生成必要的路由。对于
索引,显示、编辑、新建、创建、更新、销毁

我的猜测是,
metric.rb
文件有一个
属于:automated\u thresholding
关系,但是
metrics
数据库表缺少
automated\u thresholding\u id
字段

您应该创建一个迁移来添加该字段


add_reference:metrics,:automated_thresholding

现在,我得到了这个错误:ActionController::UrlGenerationError in metrics#index No route matches{:action=>“edit”,:controller=>“metrics”,:id=>nil}缺少必需的键:[:id]您的数据变量为零-尝试将其替换为要编辑的对象的ID删除
get
路由,然后重试。是的,删除此行
get'edit'=>“metrics”#edit'
。这已经在
resources:metrics
betterI中定义了,我肯定认为这就是问题所在。如果您的主键与id不同,请尝试此
self.primary\u key=''
为什么要添加
get
路由?我认为
resources:metrics
如果您想使用默认的rails路由模式就足够了。这是我在模型中拥有的:class Metric自动阈值的数据库表。如果是这种情况,则此语法
self.table\u name=AutomatedThresholding
是错误的。这应该是正确的
self.table\u name='automated\u thresholdings'
阅读更多信息:
<td id="EditButton"><%= link_to "Edit", edit_metric_path(data) %></td>