Skip to content

Instantly share code, notes, and snippets.

@sebastjan-hribar
Created April 20, 2016 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastjan-hribar/db90e457424940e4f51f2cdf593d1435 to your computer and use it in GitHub Desktop.
Save sebastjan-hribar/db90e457424940e4f51f2cdf593d1435 to your computer and use it in GitHub Desktop.
params validation
module Web::Controllers::Posts
class Update
include Web::Action
before :check_for_admin_role
params do
param :post do
param :title, presence: true
param :body, presence: true
end
end
def call(params)
if params.valid?
@post = PostRepository.find(params[:id])# or halt 404
title = params[:post][:title]
body = params[:post][:body]
published_at = Time.now
@post.update(title: title, body: body, published_at: published_at)
#@post.update(params[:post])
@post = PostRepository.update(@post)
redirect_to routes.post_url(id: @post.id)
else
redirect_to '/'
end
end
end
end
Boot Error
Something went wrong while loading /home/sebastjan/Dokumenti/projekti/hanami/ptconference/config.ru
NoMethodError: undefined method `update' for nil:NilClass
/home/sebastjan/Dokumenti/projekti/hanami/ptconference/apps/web/controllers/posts/update.rb:21:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-controller-0.6.1/lib/hanami/action/callbacks.rb:195:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-controller-0.6.1/lib/hanami/action/callable.rb:73:in `block in call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-controller-0.6.1/lib/hanami/action/throwable.rb:143:in `block in _rescue'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-controller-0.6.1/lib/hanami/action/throwable.rb:141:in `catch'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-controller-0.6.1/lib/hanami/action/throwable.rb:141:in `_rescue'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-controller-0.6.1/lib/hanami/action/callable.rb:69:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-router-0.6.2/lib/hanami/routing/endpoint.rb:81:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/http_router-0.11.2/lib/http_router.rb:193:in `process_destination_path'
(eval):1063:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/http_router-0.11.2/lib/http_router.rb:288:in `raw_call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-router-0.6.2/lib/hanami/routing/http_router.rb:135:in `raw_call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/http_router-0.11.2/lib/http_router.rb:142:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-router-0.6.2/lib/hanami/router.rb:931:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:153:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-0.7.0/lib/hanami/middleware.rb:52:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-0.7.0/lib/hanami/application.rb:217:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/http_router-0.11.2/lib/http_router.rb:193:in `process_destination_path'
(eval):15:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/http_router-0.11.2/lib/http_router.rb:288:in `raw_call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-router-0.6.2/lib/hanami/routing/http_router.rb:135:in `raw_call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/http_router-0.11.2/lib/http_router.rb:142:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-router-0.6.2/lib/hanami/router.rb:931:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-0.7.0/lib/hanami/static.rb:27:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:153:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-0.7.0/lib/hanami/container.rb:37:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:86:in `proceed_as_child'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:31:in `call!'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:18:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/lint.rb:49:in `_call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/lint.rb:37:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/showexceptions.rb:24:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/commonlogger.rb:33:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thin-1.6.4/lib/thin/connection.rb:86:in `block in pre_process'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thin-1.6.4/lib/thin/connection.rb:84:in `catch'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thin-1.6.4/lib/thin/connection.rb:84:in `pre_process'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thin-1.6.4/lib/thin/connection.rb:53:in `process'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thin-1.6.4/lib/thin/connection.rb:39:in `receive_data'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:193:in `run_machine'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:193:in `run'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thin-1.6.4/lib/thin/backends/base.rb:73:in `start'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thin-1.6.4/lib/thin/server.rb:162:in `start'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/handler/thin.rb:19:in `run'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-0.7.0/lib/hanami/commands/server.rb:56:in `start'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-0.7.0/lib/hanami/cli.rb:43:in `server'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
/home/sebastjan/.rvm/gems/ruby-2.2.1/gems/hanami-0.7.0/bin/hanami:5:in `<top (required)>'
/home/sebastjan/.rvm/gems/ruby-2.2.1/bin/hanami:23:in `load'
/home/sebastjan/.rvm/gems/ruby-2.2.1/bin/hanami:23:in `<main>'
/home/sebastjan/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/home/sebastjan/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
<h3>Posodobi obvestilo</h3>
<%=
form_for :post, routes.post_path(post.id), method: :patch do
table id: 'table_style' do
tr do
td do
label "Naslov"
end
td do
text_field :title, value: post.title
end
end
tr do
td do
label "Obvestilo"
end
td do
text_area :body, post.body
end
end
end
div class: 'controls' do
submit 'Potrdi', class: "vnos"
end
end
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment