Ruby on rails 未定义的方法rails活动记录
我试图显示两个表之间的关系,但我得到了Ruby on rails 未定义的方法rails活动记录,ruby-on-rails,Ruby On Rails,我试图显示两个表之间的关系,但我得到了 undefined method `guiders' for # <ActiveRecord::Relation::ActiveRecord_Relation_Trip:0x3865e78> 未定义的#的“引导者”方法 --导赏员控制器代码-- class ShowguidersController
undefined method `guiders' for # <ActiveRecord::Relation::ActiveRecord_Relation_Trip:0x3865e78>
未定义的#的“引导者”方法
--导赏员控制器代码--
class ShowguidersController
导向器模型
class Guider < ActiveRecord::Base
belongs_to :trip
end
class-Guider
出行模式
class Trip < ActiveRecord::Base
has_many :guides
end
classtrip
看法
这是我的教授给他的
<center><h1> Here are our Guides </h1>
<br /><br /><br /><br />
<table width = 60% border =1>
<tr><th>Guide # </th><th> Name </th> <th> Phone </th> </tr>
<% @guiders_out.each do |m| %>
<tr><td> <%= m.id %> </tr> </td> <tr><td> <%= m.name %> </tr> </td> <tr><td> <%= m.phone %> </tr> </td>
<% end %>
</table></center>
<br /><br /><br /><br />
以下是我们的指南
指南#姓名电话
您正在调用ActiveRecord模型集合(即关系
)上的方法
要返回每次旅行的每个向导的集合
,首先需要正确地建立关联模型。试试这个
class Guider < ActiveRecord::Base
belongs_to :trip
end
class Trip < ActiveRecord::Base
# NOTE: you must match your association name with its associated class
has_many :guiders
end
class-Guider
现在可以在控制器中聚合集合,如下所示
class ShowguidersController < ApplicationController
def guidersout
@guiders_out = Trip.all.collect(&:guiders).flatten
end
end
class ShowguidersController
您正在调用ActiveRecord模型集合(即关系
)上的方法
要返回每次旅行的每个向导的集合
,首先需要正确地建立关联模型。试试这个
class Guider < ActiveRecord::Base
belongs_to :trip
end
class Trip < ActiveRecord::Base
# NOTE: you must match your association name with its associated class
has_many :guiders
end
class-Guider
现在可以在控制器中聚合集合,如下所示
class ShowguidersController < ApplicationController
def guidersout
@guiders_out = Trip.all.collect(&:guiders).flatten
end
end
class ShowguidersController
您正在调用ActiveRecord模型集合(即关系
)上的方法
要返回每次旅行的每个向导的集合
,首先需要正确地建立关联模型。试试这个
class Guider < ActiveRecord::Base
belongs_to :trip
end
class Trip < ActiveRecord::Base
# NOTE: you must match your association name with its associated class
has_many :guiders
end
class-Guider
现在可以在控制器中聚合集合,如下所示
class ShowguidersController < ApplicationController
def guidersout
@guiders_out = Trip.all.collect(&:guiders).flatten
end
end
class ShowguidersController
您正在调用ActiveRecord模型集合(即关系
)上的方法
要返回每次旅行的每个向导的集合
,首先需要正确地建立关联模型。试试这个
class Guider < ActiveRecord::Base
belongs_to :trip
end
class Trip < ActiveRecord::Base
# NOTE: you must match your association name with its associated class
has_many :guiders
end
class-Guider
现在可以在控制器中聚合集合,如下所示
class ShowguidersController < ApplicationController
def guidersout
@guiders_out = Trip.all.collect(&:guiders).flatten
end
end
class ShowguidersController
一次旅行
有许多导游
,但没有集合
如果您想获得所有信息,请使用:
@guiders_out = r.map(&:guiders)
一次旅行
有许多向导
,但没有集合
如果您想获得所有信息,请使用:
@guiders_out = r.map(&:guiders)
一次旅行
有许多向导
,但没有集合
如果您想获得所有信息,请使用:
@guiders_out = r.map(&:guiders)
一次旅行
有许多向导
,但没有集合
如果您想获得所有信息,请使用:
@guiders_out = r.map(&:guiders)
你需要所有与所有旅行相关的导游。
请尝试使用此代码
def guidersout
@guiders_out = Guider.joins(:trip).all
end
我发现您也必须在模型中进行修改
class Trip < ActiveRecord::Base
has_many :guides, class_name: 'Guider', foreign_key: 'trip_id'
end
在您看来,请更改表格
<table width = 60% border =1>
<tr>
<th>Guide # </th>
<th> Name </th>
<th> Phone </th>
</tr>
<% @guiders_out.each do |m| %>
<tr>
<td> <%= m.id %> </td>
<td> <%= m.name %> </td>
<td> <%= m.phone %></td>
</tr>
<% end %>
指南#
名称
电话
您需要所有与所有行程相关的导游。
请尝试使用此代码
def guidersout
@guiders_out = Guider.joins(:trip).all
end
我发现您也必须在模型中进行修改
class Trip < ActiveRecord::Base
has_many :guides, class_name: 'Guider', foreign_key: 'trip_id'
end
在您看来,请更改表格
<table width = 60% border =1>
<tr>
<th>Guide # </th>
<th> Name </th>
<th> Phone </th>
</tr>
<% @guiders_out.each do |m| %>
<tr>
<td> <%= m.id %> </td>
<td> <%= m.name %> </td>
<td> <%= m.phone %></td>
</tr>
<% end %>
指南#
名称
电话
您需要所有与所有行程相关的导游。
请尝试使用此代码
def guidersout
@guiders_out = Guider.joins(:trip).all
end
我发现您也必须在模型中进行修改
class Trip < ActiveRecord::Base
has_many :guides, class_name: 'Guider', foreign_key: 'trip_id'
end
在您看来,请更改表格
<table width = 60% border =1>
<tr>
<th>Guide # </th>
<th> Name </th>
<th> Phone </th>
</tr>
<% @guiders_out.each do |m| %>
<tr>
<td> <%= m.id %> </td>
<td> <%= m.name %> </td>
<td> <%= m.phone %></td>
</tr>
<% end %>
指南#
名称
电话
您需要所有与所有行程相关的导游。
请尝试使用此代码
def guidersout
@guiders_out = Guider.joins(:trip).all
end
我发现您也必须在模型中进行修改
class Trip < ActiveRecord::Base
has_many :guides, class_name: 'Guider', foreign_key: 'trip_id'
end
在您看来,请更改表格
<table width = 60% border =1>
<tr>
<th>Guide # </th>
<th> Name </th>
<th> Phone </th>
</tr>
<% @guiders_out.each do |m| %>
<tr>
<td> <%= m.id %> </td>
<td> <%= m.name %> </td>
<td> <%= m.phone %></td>
</tr>
<% end %>
指南#
名称
电话
你需要使用指南而不是指南你是想写有很多:指南而不是有很多:指南吗?你需要使用指南而不是指南你是想写有很多:指南而不是有很多:指南吗?你是想写有很多:指南吗有很多:指南
而不是有很多:指南
?你需要使用指南而不是指南你的意思是写有很多:指南
而不是有很多:指南
?我把它放进去,得到了指南:模块的错误未定义方法“arel\u table”,我把它放进去,得到了错误未定义方法“arel\u table”对于Guide:ModuleI输入并获得错误未定义方法'arel_table'对于Guide:ModuleI输入并获得错误未定义方法'arel_table'对于Guide:ModuleI尝试并获得showguiders控制器#guiders中的错误代码nomethoder错误#对于#您可能需要检查您的