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
99
Surrounded by Microservices
damirsvrtan
2
4.9k
Building Serverless Ruby Bots @ Ruby Conf 2018
damirsvrtan
0
300
Building Serverless Ruby Bots @ Paris.rb Conf 2018
damirsvrtan
1
1.8k
Importing and serving millions of records
damirsvrtan
1
110
Stateless authentication w/ JSON Web Tokens
damirsvrtan
5
260
Building Ruby Bots on AWS Lambda
damirsvrtan
0
950
Reinventing The Bootcamp Idea
damirsvrtan
0
140
Other Decks in Programming
See All in Programming
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
190
PHP8.3の機能を振り返る / Review of PHP 8.3 features
seike460
PRO
1
110
Designing for tomorrow's programming workflows
honnibal
PRO
2
120
ゆるい個人開発のススメ
kuroppe1819
10
980
Git Rebase
bkuhlmann
11
1.6k
今、知っておきたい! 生成AIエージェントの世界
elith
3
350
Ruby Pattern Matching
bkuhlmann
0
920
MicrosoftのPlatform Engineeringガイドを読んで実際になにかやってみた
ymd65536
1
270
코틀린으로 멀티플랫폼 만들기
pangmoo
0
140
チーム力を高めるスクラム実践法:カンバン公開と課題攻略について - ニフティのスクラムトーク Vol. 2 - NIFTY Tech Talk #18
niftycorp
PRO
1
110
エンターテイメント業界で利用されるAWS
demuyan
0
210
Random\Randomizer クラスで日常のあれこれを解決しよう! / Random\Randomizer class solves familiar trouble
cocoeyes02
0
150
Featured
See All Featured
Embracing the Ebb and Flow
colly
79
4.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
273
13k
Building Your Own Lightsaber
phodgson
98
5.7k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
Making Projects Easy
brettharned
108
5.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
9
8.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
398
65k
Fantastic passwords and where to find them - at NoRuKo
philnash
36
2.5k
It's Worth the Effort
3n
180
27k
Bootstrapping a Software Product
garrettdimon
PRO
301
110k
The Illustrated Children's Guide to Kubernetes
chrisshort
30
46k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
77
42k
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.