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
41
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
420
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
110
Surrounded by Microservices
damirsvrtan
2
5k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
330
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
1.9k
Importing and serving millions of records
damirsvrtan
1
110
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
270
Building Ruby Bots on AWS Lambda
damirsvrtan
0
1k
Reinventing The Bootcamp Idea
damirsvrtan
0
150
Other Decks in Programming
See All in Programming
Rubyのパフォーマンスプロファイリングの改善 / Enhancing performance profiling for Ruby
osyoyu
1
410
Android開発者のための Kotlin Multiplatform入門
ntaro
0
190
生成AIをkintoneに連携してみた
hideg
0
230
「2024年版 Kotlin サーバーサイドプログラミング実践開発」の補講 〜O/Rマッパー編〜
n_takehata
2
260
CSC307 Lecture 11
javiergs
PRO
0
240
Product Management LT会_クアンド新家
shinshin
0
260
ピグパーティにおけるMongoDB CommunityバージョンからAtlasへの移行事例
10969hotaka
0
130
Rustのweb開発を助ける 便利なツール紹介
yuki0418
1
190
企業向け生成AIアプリの 開発から得られた知見
takaakikakei
0
310
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
2
81k
12年前の『型システム入門』翻訳の思い出話
mame
11
1.2k
大規模マルチテナントを解決するYugabyteDBという選択肢
nnaka2992
1
250
Featured
See All Featured
Debugging Ruby Performance
tmm1
71
11k
Designing the Hi-DPI Web
ddemaree
276
34k
The MySQL Ecosystem @ GitHub 2015
samlambert
248
12k
For a Future-Friendly Web
brad_frost
173
9.2k
Automating Front-end Workflow
addyosmani
1362
200k
The Illustrated Children's Guide to Kubernetes
chrisshort
39
47k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
13
430
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
26
2.1k
StorybookのUI Testing Handbookを読んだ
zakiyama
15
4.9k
Navigating Team Friction
lara
181
13k
We Have a Design System, Now What?
morganepeng
46
7k
Fireside Chat
paigeccino
25
2.8k
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.