if there's only one item search result, redirect to it

This commit is contained in:
Emi Matchu 2013-07-09 19:54:22 -07:00
parent 4c208c9ac3
commit 72c59f0b68
2 changed files with 10 additions and 2 deletions

View file

@ -18,8 +18,12 @@ class ItemsController < ApplicationController
assign_closeted! assign_closeted!
respond_to do |format| respond_to do |format|
format.html { format.html {
@items.prepare_partial(:item_link_partial) if @items.size == 1
render redirect_to @items.first
else
@items.prepare_partial(:item_link_partial)
render
end
} }
format.json { format.json {
@items.prepare_method(:as_json) @items.prepare_method(:as_json)

View file

@ -7,6 +7,10 @@ class Item
delegate :description, :name, :nc?, :thumbnail_url, :to_param, to: :item delegate :description, :name, :nc?, :thumbnail_url, :to_param, to: :item
def self.model_name
Item.model_name
end
def initialize(id) def initialize(id)
@id = id @id = id
@known_outputs = {method: {}, partial: {}} @known_outputs = {method: {}, partial: {}}