Permalink
Browse files

Merge commit '48a292c5f1c5dd15ac4a272a9ddd5dd4eac5c86d' into HEAD

  • Loading branch information...
2 parents ec3d386 + 48a292c commit d55b8f4c82ea6656b150d38344033e1915dffc7c Jenkins committed May 9, 2012
Showing with 7 additions and 8 deletions.
  1. +3 −5 app/controllers/artefacts_controller.rb
  2. +4 −3 app/models/artefact.rb
View
8 app/controllers/artefacts_controller.rb
@@ -1,5 +1,4 @@
class ArtefactsController < ApplicationController
- before_filter :redirect_to_show_if_need_met, :only => :new
before_filter :find_artefact, :only => [:show, :edit, :update]
before_filter :build_artefact, :only => [:new, :create]
@@ -17,16 +16,15 @@ def show
end
def new
+ redirect_to_show_if_need_met
end
def edit
end
def create
@artefact.save
- location = @artefact.admin_url
- location += '?return_to=' + params[:return_to] if params[:return_to]
- respond_with @artefact, location: location
+ respond_with @artefact, location: @artefact.admin_url(params.slice(:return_to))
end
def update
@@ -44,7 +42,7 @@ def update
private
def redirect_to_show_if_need_met
- if params[:artefact] and params[:artefact][:need_id]
+ if params[:artefact] && params[:artefact][:need_id]
artefact = Artefact.where(need_id: params[:artefact][:need_id]).first
redirect_to artefact if artefact
end
View
7 app/models/artefact.rb
@@ -90,9 +90,10 @@ def normalise
self.kind = KIND_TRANSLATIONS[kind.to_s.downcase.strip]
end
- def admin_url
- app = Plek.current.find owning_app
- app += '/admin/publications/' + id.to_s
+ def admin_url(options = {})
+ [ "#{Plek.current.find(owning_app)}/admin/publications/#{id}",
+ options.to_query
+ ].reject(&:blank?).join("?")
end
# TODO: Replace this nonsense with a proper API layer.

0 comments on commit d55b8f4

Please sign in to comment.