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
52
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
460
Crossing Domain Boundaries with GraphQL
damirsvrtan
0
150
Surrounded by Microservices
damirsvrtan
2
5.2k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
410
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
2.2k
Importing and serving millions of records
damirsvrtan
1
150
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
310
Building Ruby Bots on AWS Lambda
damirsvrtan
0
1.2k
Reinventing The Bootcamp Idea
damirsvrtan
0
200
Other Decks in Programming
See All in Programming
Java on Azure で LangGraph!
kohei3110
0
160
生成AIで日々のエラー調査を進めたい
yuyaabo
0
610
Effect の双対、Coeffect
yukikurage
5
1.4k
ドメインモデリングにおける抽象の役割、tagless-finalによるDSL構築、そして型安全な最適化
knih
11
1.9k
関数型まつり2025登壇資料「関数プログラミングと再帰」
taisontsukada
2
840
Webからモバイルへ Vue.js × Capacitor 活用事例
naokihaba
0
730
技術懸念に立ち向かい 法改正を穏便に乗り切った話
pop_cashew
0
1.5k
ktr0731/go-mcpでMCPサーバー作ってみた
takak2166
0
170
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
250
社内での開発コミュニティ活動とモジュラーモノリス標準化事例のご紹介/xPalette and Introduction of Modular monolith standardization
m4maruyama
1
130
GoのGenericsによるslice操作との付き合い方
syumai
2
670
赤裸々に公開。 TSKaigiのオフシーズン
takezoux2
0
140
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
24
1.7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.8k
How to Ace a Technical Interview
jacobian
277
23k
Balancing Empowerment & Direction
lara
1
340
Designing Experiences People Love
moore
142
24k
Visualization
eitanlees
146
16k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.9k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
Music & Morning Musume
bryan
46
6.6k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
For a Future-Friendly Web
brad_frost
179
9.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.