Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.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 Rails Link_to正在链接到不需要的视图_Ruby On Rails_Ruby_Routes_Rails Routing_Link To - Fatal编程技术网

Ruby on rails Rails Link_to正在链接到不需要的视图

Ruby on rails Rails Link_to正在链接到不需要的视图,ruby-on-rails,ruby,routes,rails-routing,link-to,Ruby On Rails,Ruby,Routes,Rails Routing,Link To,在我的视图中,我的链接指向一个完全不同于我所希望的“show.html.erb”。我基本上是想理解为什么@exhibit的“链接”链接到一个“调查”档案。我认为这可能与我的路由文件有关,或者是因为它是一个“属于”关系……但似乎无法正常工作……那链接应该是什么 更新:(根据BROIS问题) 缺少的行为不端链接位于in show.html.erb中 <%= link_to investigation_exhibit_path(@investigation, @exhibit) do %>

在我的视图中,我的链接指向一个完全不同于我所希望的“show.html.erb”。我基本上是想理解为什么@exhibit的“链接”链接到一个“调查”档案。我认为这可能与我的路由文件有关,或者是因为它是一个“属于”关系……但似乎无法正常工作……那链接应该是什么

更新:(根据BROIS问题) 缺少的行为不端链接位于in show.html.erb中

<%= link_to investigation_exhibit_path(@investigation, @exhibit) do %>
MY EXHIBIT.RB(模型)

最后是MY SHOW.HTML.ERB(调查档案)


添加了调查控制员

class InvestigationsController < ApplicationController


def new
  @investigation = Investigation.new
end

def show
   @investigation = Investigation.find(params[:id])
end

def index
  @investigations = Investigation.paginate(page: params[:page])
end

def create
  @investigation = Investigation.new(params[:investigation])
  if @investigation.save
    flash[:success] = "You've successfully created..."
    redirect_to @investigation
  else
    render 'new'
  end
end

end
类调查控制器
增加了调查模型

class Investigation < ActiveRecord::Base
  # belongs_to :user

  has_many :players, dependent: :destroy
  has_many :exhibits, dependent: :destroy


  default_scope -> { order('created_at DESC') }
end
课堂调查{order('created_at DESC')}
结束

非常感谢您的帮助……如果我需要发布更多信息,请在您的:app/contorollers/expensions\u controller.rb中告诉我

def show
@investigation = Investigation.find(params[:investigation_id])
@exhibit = Exhibit.find(params[:id])
end
在您的应用程序中:app/views/examples/show.html.erb

<%= link_to investigation_exhibit_path(@investigation, @exhibit) do %>


可能吧,我想。

您使用的是@investment变量,但它不是在show action中设置的。它是在视图中的某个位置设置的,还是“创建”视图?请澄清在该视图的代码中显示了哪个视图中存在假定的行为不端链接。您有“调查配置文件”“在
show.html
.erb
后面的括号中,但不清楚这是什么意思。您是否有一个
InvestigationProfile`类尚未共享?@BroiSatse我想我明白了…@调查设置在我的调查模型/控制器内…(所有展品都属于调查)。BroiSatse,因此显示的show.html.erb是针对调查配置文件的(我有一个调查模型和控制器,但我不认为我需要发布它…现在就可以了。)我希望@exhibit的这个链接链接链接到exhibit show.html.erb刚刚用调查模型和控制器更新过…有什么想法吗?谢谢你,当我这样做时,它会在调查配置文件(show.html.erb)上给我以下错误“没有路线匹配{:action=>“show”,:controller=>“expensions”,:investment\u id=>“我想你是在为controller赚钱……但是视图中的链接似乎仍然关闭。感谢你的帮助,HeungjuGot it……只需要(@investment,expension)。谢谢你。
class Investigation < ActiveRecord::Base
  # belongs_to :user

  has_many :players, dependent: :destroy
  has_many :exhibits, dependent: :destroy


  default_scope -> { order('created_at DESC') }
end
def show
@investigation = Investigation.find(params[:investigation_id])
@exhibit = Exhibit.find(params[:id])
end
<%= link_to investigation_exhibit_path(@investigation, @exhibit) do %>