Skip to content

Commit

Permalink
Turn url_params keys into strings
Browse files Browse the repository at this point in the history
  • Loading branch information
gcapizzi committed Aug 10, 2013
1 parent 4dc4f2e commit 2b9bfc6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/actions/accounts_actions.rb
Expand Up @@ -20,7 +20,7 @@ def call(env)

class ShowAccount < AccountsAction
def call(env)
id = req(env).url_params[:account_id].to_i
id = req(env).url_params['account_id'].to_i
account = @repository.get(id) or return not_found
body = @renderer.render(account)
ok(body)
Expand All @@ -31,7 +31,7 @@ class UpdateAccount < AccountsAction
def call(env)
req = req(env)

id = req.url_params[:account_id].to_i
id = req.url_params['account_id'].to_i
account = @repository.get(id) or return not_found

account.set(req.params)
Expand Down Expand Up @@ -59,7 +59,7 @@ def call(env)

class DeleteAccount < AccountsAction
def call(env)
id = req(env).url_params[:account_id].to_i
id = req(env).url_params['account_id'].to_i
account = @repository.get(id) or return not_found

if @repository.destroy(account)
Expand Down
2 changes: 1 addition & 1 deletion app/actions/transactions_actions.rb
Expand Up @@ -12,7 +12,7 @@ def initialize(accounts_repository, renderer)
end

def call(env)
account_id = req(env).url_params[:account_id].to_i
account_id = req(env).url_params['account_id'].to_i
account = @accounts_repository.get(account_id)
body = @renderer.render(account.transactions)
ok(body)
Expand Down
8 changes: 7 additions & 1 deletion app/utils.rb
Expand Up @@ -4,7 +4,13 @@ module Scrooge

class Request < Rack::Request
def url_params
env['rack.routing_args']
stringify_keys(env['rack.routing_args'])
end

private

def stringify_keys(hash)
Hash[hash.to_a.map { |key, val| [key.to_s, val] }]
end
end

Expand Down

0 comments on commit 2b9bfc6

Please sign in to comment.