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
450
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
130
Surrounded by Microservices
damirsvrtan
2
5.1k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
390
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
2.1k
Importing and serving millions of records
damirsvrtan
1
140
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
300
Building Ruby Bots on AWS Lambda
damirsvrtan
0
1.1k
Reinventing The Bootcamp Idea
damirsvrtan
0
180
Other Decks in Programming
See All in Programming
DRFを少しずつ オニオンアーキテクチャに寄せていく DjangoCongress JP 2025
nealle
2
280
SwiftUI移行のためのインプレッショントラッキング基盤の構築
kokihirokawa
0
160
kintone開発を効率化するためにチームで試した施策とその結果を大放出!
oguemon
0
180
Lambdaの監視、できてますか?Datadogを用いてLambdaを見守ろう
nealle
0
100
15分で学ぶDuckDBの可愛い使い方 DuckDBの最近の更新
notrogue
3
750
生成AIで加速するテスト実装 - ロリポップ for Gamersの事例と 生成AIエディタの活用
kinosuke01
0
130
ナレッジイネイブリングにAIを活用してみる ゆるSRE勉強会 #9
nealle
0
160
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
960
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the benefits are huge)
lmammino
1
160
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
160
TCAを用いたAmebaのリアーキテクチャ
dazy
0
210
Drawing Heighway’s Dragon- Recursive Function Rewrite- From Imperative Style in Pascal 64 To Functional Style in Scala 3
philipschwarz
PRO
0
100
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Rails Girls Zürich Keynote
gr2m
94
13k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
30
4.6k
Building an army of robots
kneath
303
45k
Docker and Python
trallard
44
3.3k
Code Reviewing Like a Champion
maltzj
521
39k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Building Your Own Lightsaber
phodgson
104
6.2k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
Scaling GitHub
holman
459
140k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
11
1.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
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.