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
71
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Responders
Dry-out your controllers with some responders
DamirSvrtan
September 14, 2015
More Decks by DamirSvrtan
See All by DamirSvrtan
Designing APIs: Less Data is More
damirsvrtan
1
540
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
210
Surrounded by Microservices
damirsvrtan
2
5.5k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
490
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
2.6k
Importing and serving millions of records
damirsvrtan
1
230
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
380
Building Ruby Bots on AWS Lambda
damirsvrtan
0
1.3k
Reinventing The Bootcamp Idea
damirsvrtan
0
290
Other Decks in Programming
See All in Programming
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
130
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.3k
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
260
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
1
830
まだ間に合う!今年の夏こそSchemeのマクロ展開器を完全理解!
omasanori
0
570
バグを直したら useEffect が消えた
colorful12
3
770
Go を使い始めて 2 ヶ月の学び / My first two months with Go
contour_gara
0
390
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
740
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
230
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
240
引き算の組織 ― アウトカムとAIに全振りするために辞めたこと ― / Organization by Subtraction
hirokiyamamoto14
PRO
0
310
Hono + Inertia + React で LP を構築した話
oukayuka
2
180
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Producing Creativity
orderedlist
PRO
348
40k
Between Models and Reality
mayunak
4
410
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.9k
Color Theory Basics | Prateek | Gurzu
gurzu
0
440
Music & Morning Musume
bryan
47
7.3k
Optimizing for Happiness
mojombo
378
71k
How to make the Groovebox
asonas
2
2.4k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
500
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.