app/controllers/dataclips/clips_controller.rb in dataclips-0.0.1 vs app/controllers/dataclips/clips_controller.rb in dataclips-0.0.2
- old
+ new
@@ -1,40 +1,37 @@
module Dataclips
class ClipsController < ApplicationController
def show
@clip_id = params[:clip_id]
- begin
- initialize_clip(@clip_id)
- rescue
- raise ActionController::RoutingError.new('Not Found')
- end
+ if initialize_clip(@clip_id)
+ @headers = localize_headers(@clip_id, @schema.keys)
- @headers = localize_headers(@clip_id, @schema.keys)
+ @clip = @klass.new params.slice(*@variables.keys)
- @clip = @klass.new params.slice(*@variables.keys)
-
- respond_to do |format|
- format.html do
- begin
- require_parameters
- rescue ActionController::ParameterMissing => e
- @error = e
- render :edit
+ respond_to do |format|
+ format.html do
+ begin
+ require_parameters
+ rescue ActionController::ParameterMissing => e
+ @error = e
+ render :require_variables
+ end
end
- end
- format.json do
- begin
- process_json(@clip, params[:page])
- rescue ActiveRecord::StatementInvalid => e
- render json: e.message, status: :unprocessable_entity
+ format.json do
+ begin
+ require_parameters
+ render_json_records(@clip, params[:page])
+ rescue ActiveRecord::StatementInvalid => e
+ render json: e.message, status: :unprocessable_entity
+ end
end
end
+ else
+ raise ActionController::RoutingError.new('Not Found')
end
end
-
- def edit; end
private
def require_parameters
@variables.keys.map(&:to_sym).each do |variable|