Class: WhurlEngine::WhurlsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/whurl_engine/whurls_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/whurl_engine/whurls_controller.rb', line 7

def create
  request_params = params[:whurl]
  request_params[:request_headers] = HTTParty::Response::Headers.new(Hash[params[:header_keys].zip(params[:header_values])].delete_if { |k, _| k.blank? })
  request_params[:request_parameters] = Hash[params[:param_keys].zip(params[:param_values])].delete_if { |k, _| k.blank? }
  @whurl = Whurl.new(request_params)

  unless @whurl.save
    flash[:alert] = @whurl.errors.map {|k,v| "#{k.to_s.titleize} #{v}"}.join('\n')
    render :new and return
  end
  redirect_to short_whurl_path(@whurl)
end

#destroyObject



31
32
33
34
35
36
# File 'app/controllers/whurl_engine/whurls_controller.rb', line 31

def destroy
  @whurl = Whurl.find_by_hash_key(params[:id])
  unless @whurl.destroy
    render :partial => 'whurl_engine/shared/error', :locals => {:object => @whurl}
  end
end

#editObject



20
21
22
# File 'app/controllers/whurl_engine/whurls_controller.rb', line 20

def edit
  @whurl = Whurl.find_by_hash_key(params[:id])
end

#newObject



3
4
5
# File 'app/controllers/whurl_engine/whurls_controller.rb', line 3

def new
  @whurl = Whurl.new
end

#showObject



38
39
40
# File 'app/controllers/whurl_engine/whurls_controller.rb', line 38

def show
  @whurl = Whurl.find_by_hash_key(params[:id])
end

#updateObject



24
25
26
27
28
29
30
# File 'app/controllers/whurl_engine/whurls_controller.rb', line 24

def update
  @whurl = Whurl.find_by_hash_key(params[:id])
  unless @whurl.update_attributes(params[:whurl])
    render :partial => 'whurl_engine/shared/error', :locals => {:object => @whurl}
  end
  redirect_to resource_path(params[:whurl][:resource_id])
end