Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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 RubyonRails实现了通用搜索_Ruby On Rails_Search - Fatal编程技术网

Ruby on rails RubyonRails实现了通用搜索

Ruby on rails RubyonRails实现了通用搜索,ruby-on-rails,search,Ruby On Rails,Search,我的数据库中有两个表-一个“疾病”表和一个“症状”表。 我已经实现了搜索两个表的通用搜索。 我的目标是在结果页面中显示结果,每个结果都应该是指向结果“显示”页面(疾病/id/show或症状/id/show)的超链接 当我将一般结果传递到结果页面时,我真的不知道当前结果是一种疾病还是一种症状。我想知道获取此信息的最佳方式是什么(我是否应该尝试在控制器中收集此信息并以某种方式将其传递给html?我是否应该以某种方式从html运行另一个查询?) 我使用的是rails 3.x,我的控制器代码如下所示:

我的数据库中有两个表-一个“疾病”表和一个“症状”表。 我已经实现了搜索两个表的通用搜索。 我的目标是在结果页面中显示结果,每个结果都应该是指向结果“显示”页面(疾病/id/show或症状/id/show)的超链接

当我将一般结果传递到结果页面时,我真的不知道当前结果是一种疾病还是一种症状。我想知道获取此信息的最佳方式是什么(我是否应该尝试在控制器中收集此信息并以某种方式将其传递给html?我是否应该以某种方式从html运行另一个查询?)

我使用的是rails 3.x,我的控制器代码如下所示:

class SearchController < ApplicationController
    def index
        @results = Illness.search(params[:search]) + Symptom.search(params[:search])

        respond_to do |format|
            format.html # index.html.erb
            format.json { render json: @results }
        end
    end
end
class SearchController
谢谢,

你不必担心。让轨道为其服务:

   - @results.each do |result|
     = link_to 'Show', result
您将根据结果的类型获得适当的链接


还有一个。URL中的
show
与示例中的
show
操作有什么关系,例如:
symptom/id/show
?默认情况下,
show
操作映射到
GET/model/id
路径。

wow。谢谢这门语言有很多东西要学。谢谢你对链接的评论。