我想知道执行下一个任务的最佳做法是什么。
我有一个搜索结果要从索引操作中显示。每个单独的记录都通过显示操作显示在弹出窗口中。
如果只找到一条记录,我想做的是执行弹出窗口。
这是我已经尝试过的。
def index
@companies = Company.search(params[:query]).results
@count = @companies.total
if @count == 1
return
render company_path
end
结尾
似乎return,redirect_to或render在一个动作中不能很好地发挥作用。
还有其他想法吗?
更新添加了显示操作
def show
sleep 1/2
client = Elasticsearch::Client.new host:'127.0.0.1:9200', log: true
response = client.search index: 'companies', body: {query: { match: {_id: params[:id]} } }
@company = response['hits']['hits'][0]['_source']
respond_to do |format|
format.html # show.html.erb
format.js # show.js.erb
format.json { render json: @company }
end
# more code
end