Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Responders
Search
DamirSvrtan
September 14, 2015
Programming
0
45
Responders
Dry-out your controllers with some responders
DamirSvrtan
September 14, 2015
Tweet
Share
More Decks by DamirSvrtan
See All by DamirSvrtan
Designing APIs: Less Data is More
damirsvrtan
1
430
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
120
Surrounded by Microservices
damirsvrtan
2
5.1k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
370
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
2k
Importing and serving millions of records
damirsvrtan
1
130
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
280
Building Ruby Bots on AWS Lambda
damirsvrtan
0
1.1k
Reinventing The Bootcamp Idea
damirsvrtan
0
170
Other Decks in Programming
See All in Programming
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
useSyncExternalStoreを使いまくる
ssssota
6
1k
Jakarta EE meets AI
ivargrimstad
0
240
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
103 Early Hints
sugi_0000
1
230
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
380
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
From Translations to Multi Dimension Entities
alexanderschranz
2
130
Featured
See All Featured
Faster Mobile Websites
deanohume
305
30k
A designer walks into a library…
pauljervisheath
204
24k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Six Lessons from altMBA
skipperchong
27
3.5k
Music & Morning Musume
bryan
46
6.2k
A Modern Web Designer's Workflow
chriscoyier
693
190k
A better future with KSS
kneath
238
17k
BBQ
matthewcrist
85
9.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Unsuck your backbone
ammeep
669
57k
Transcript
Responders
©2015 Infinum student academy PostsController#create @post = Post.new(post_params) if @post.save(post_params)
redirect_to @post flash[:notice] = 'Post was successfully updated.' else render :new end
©2015 Infinum student academy What about internationalization?
©2015 Infinum student academy PostsController#create @post = Post.new(post_params) if @post.save
flash[:notice] = I18n.t(‘flash.posts.create.notice’) redirect_to @post else render :new end
©2015 Infinum student academy The update action is very similar
©2015 Infinum student academy PostsController#update @post = Post.find(params[:id]) if @post.update(post_params)
flash[:notice] = I18n.t(‘flash.posts.update.notice’) redirect_to @post else render :edit end
©2015 Infinum student academy The restful controller pseudocode: initialize_resource can
it be saved? flash redirect else render end
Meet the responders..
©2015 Infinum student academy Convenient wrappers for REST controllers @post
= Post.create(post_params) respond_with @post
©2015 Infinum student academy Knows what translation to look at
©2015 Infinum student academy Universal translation for all controllers flash:
actions: create: notice: "%{resource_name} was successfully created." update: notice: "%{resource_name} was successfully updated." destroy: notice: "%{resource_name} was successfully destroyed." alert: "%{resource_name} could not be destroyed."
©2015 Infinum student academy Translation per controller flash: posts: create:
notice: "Your post was created and will be published soon"
©2015 Infinum student academy Need a non-standard redirect location? @post
= Post.create(post_params) respond_with @post, location: -> { posts_path }
©2015 Infinum student academy Need a non-standard rendering template? @post
= Post.create(post_params) respond_with @post, action: ‘shared/posts/new’
History
©2015 Infinum student academy Responders • Extracted from Rails 4.2
to a separate gem • Maintained by Plataformatec • authors of Devise & Simple Form
©2015 Infinum student academy Why were they extracted from Rails?
©2015 Infinum student academy respond_to do |format| format.xml { render
xml: @model } format.json { render json: @model } end is clearer than… respond_with @model
©2015 Infinum student academy I only use them for Html
API’s
Fin.