From 72c59f0b68c4b8b2cf4dcacabb308bca72448b95 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 9 Jul 2013 19:54:22 -0700 Subject: [PATCH] if there's only one item search result, redirect to it --- app/controllers/items_controller.rb | 8 ++++++-- app/models/item/proxy.rb | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 38f9b367..f29a2d11 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -18,8 +18,12 @@ class ItemsController < ApplicationController assign_closeted! respond_to do |format| format.html { - @items.prepare_partial(:item_link_partial) - render + if @items.size == 1 + redirect_to @items.first + else + @items.prepare_partial(:item_link_partial) + render + end } format.json { @items.prepare_method(:as_json) diff --git a/app/models/item/proxy.rb b/app/models/item/proxy.rb index e31c789d..0a2967cb 100644 --- a/app/models/item/proxy.rb +++ b/app/models/item/proxy.rb @@ -7,6 +7,10 @@ class Item delegate :description, :name, :nc?, :thumbnail_url, :to_param, to: :item + def self.model_name + Item.model_name + end + def initialize(id) @id = id @known_outputs = {method: {}, partial: {}}